WEB-46838 WEB-41768 WEB-47551 Commit document after template expansion in case of multiple carets

IDEA-CR-68587

GitOrigin-RevId: f88a3f15cb8daa2bf096dd06b6d82908c189bb46
This commit is contained in:
Piotr Tomiak
2020-11-13 16:02:10 +01:00
committed by intellij-monorepo-bot
parent 816e9df618
commit 5bb31077db
3 changed files with 6 additions and 3 deletions

View File

@@ -63,6 +63,9 @@ public class CustomTemplateCallback {
return myFile;
}
/**
* This method may return outdated PSI on uncommitted document.
*/
@NotNull
public PsiElement getContext() {
return getContext(myFile, getOffset(), myInInjectedFragment);

View File

@@ -124,9 +124,6 @@ public class TemplateManagerImpl extends TemplateManager implements Disposable {
if (runnable != null) {
PsiDocumentManager.getInstance(myProject).commitDocument(editor.getDocument());
runnable.run();
if (editor.getCaretModel().getCaretCount() > 1) {
PsiDocumentManager.getInstance(myProject).commitDocument(editor.getDocument());
}
}
return runnable != null;
}

View File

@@ -110,6 +110,9 @@ public class ZenCodingTemplate extends CustomLiveTemplateBase {
}
try {
expand(key, callback, defaultGenerator, Collections.emptyList(), true, Registry.intValue("emmet.segments.limit"));
if (callback.getEditor().getCaretModel().getCaretCount() > 1) {
PsiDocumentManager.getInstance(callback.getProject()).commitDocument(callback.getEditor().getDocument());
}
}
catch (EmmetException e) {
CommonRefactoringUtil.showErrorHint(callback.getProject(), callback.getEditor(), e.getMessage(), XmlBundle.message("emmet.error"), "");