From 5bb31077dbf987b0b414c4d37778932b87df26f9 Mon Sep 17 00:00:00 2001 From: Piotr Tomiak Date: Fri, 13 Nov 2020 16:02:10 +0100 Subject: [PATCH] WEB-46838 WEB-41768 WEB-47551 Commit document after template expansion in case of multiple carets IDEA-CR-68587 GitOrigin-RevId: f88a3f15cb8daa2bf096dd06b6d82908c189bb46 --- .../intellij/codeInsight/template/CustomTemplateCallback.java | 3 +++ .../codeInsight/template/impl/TemplateManagerImpl.java | 3 --- .../intellij/codeInsight/template/emmet/ZenCodingTemplate.java | 3 +++ 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/codeInsight/template/CustomTemplateCallback.java b/platform/lang-impl/src/com/intellij/codeInsight/template/CustomTemplateCallback.java index f6b7f237ab33..76a6d1428be3 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/template/CustomTemplateCallback.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/template/CustomTemplateCallback.java @@ -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); diff --git a/platform/lang-impl/src/com/intellij/codeInsight/template/impl/TemplateManagerImpl.java b/platform/lang-impl/src/com/intellij/codeInsight/template/impl/TemplateManagerImpl.java index 4380e7b586d2..c9b01c5a2974 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/template/impl/TemplateManagerImpl.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/template/impl/TemplateManagerImpl.java @@ -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; } diff --git a/xml/impl/src/com/intellij/codeInsight/template/emmet/ZenCodingTemplate.java b/xml/impl/src/com/intellij/codeInsight/template/emmet/ZenCodingTemplate.java index 445831cea2d5..f50deae673ad 100644 --- a/xml/impl/src/com/intellij/codeInsight/template/emmet/ZenCodingTemplate.java +++ b/xml/impl/src/com/intellij/codeInsight/template/emmet/ZenCodingTemplate.java @@ -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"), "");