diff --git a/platform/lang-impl/src/com/intellij/codeInsight/generation/surroundWith/SurroundWithHandler.java b/platform/lang-impl/src/com/intellij/codeInsight/generation/surroundWith/SurroundWithHandler.java index 44316279bc0e..338fd74e3ce5 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/generation/surroundWith/SurroundWithHandler.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/generation/surroundWith/SurroundWithHandler.java @@ -66,7 +66,7 @@ public class SurroundWithHandler implements CodeInsightActionHandler{ } public boolean startInWriteAction() { - return false; + return true; } public static void invoke(final Project project, final Editor editor, PsiFile file, Surrounder surrounder){ diff --git a/platform/lang-impl/src/com/intellij/codeInsight/template/impl/SurroundWithTemplateHandler.java b/platform/lang-impl/src/com/intellij/codeInsight/template/impl/SurroundWithTemplateHandler.java index e17b016a84b0..ed3c695a9a7c 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/template/impl/SurroundWithTemplateHandler.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/template/impl/SurroundWithTemplateHandler.java @@ -103,28 +103,23 @@ public class SurroundWithTemplateHandler implements CodeInsightActionHandler { } public static ArrayList getApplicableTemplates(Editor editor, PsiFile file, boolean selection) { - int offset = editor.getCaretModel().getOffset(); - int startOffset = offset; - if (selection && editor.getSelectionModel().hasSelection()) { - final int selStart = editor.getSelectionModel().getSelectionStart(); - final int selEnd = editor.getSelectionModel().getSelectionEnd(); - startOffset = (offset == selStart) ? selEnd : selStart; - } + file = (PsiFile)file.copy(); + final Document document = file.getViewProvider().getDocument(); + assert document != null; - if (!selection) { - file = (PsiFile)file.copy(); - final Document document = file.getViewProvider().getDocument(); - assert document != null; - document.insertString(offset, CompletionUtil.DUMMY_IDENTIFIER_TRIMMED); - PsiDocumentManager.getInstance(file.getProject()).commitDocument(document); + int startOffset = editor.getCaretModel().getOffset(); + if (selection && editor.getSelectionModel().hasSelection()) { + startOffset = editor.getSelectionModel().getSelectionStart(); + document.deleteString(startOffset, editor.getSelectionModel().getSelectionEnd()); } - + document.insertString(startOffset, CompletionUtil.DUMMY_IDENTIFIER_TRIMMED); + PsiDocumentManager.getInstance(file.getProject()).commitDocument(document); + ArrayList list = new ArrayList(); for (TemplateImpl template : TemplateSettings.getInstance().getTemplates()) { if (!template.isDeactivated() && template.isSelectionTemplate() == selection && - (TemplateManagerImpl.isApplicable(file, offset, template) || - (selection && TemplateManagerImpl.isApplicable(file, startOffset, template)))) { + TemplateManagerImpl.isApplicable(file, startOffset, template)) { list.add(template); } } 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 ffbce303141f..e1b5a73cb9a4 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 @@ -486,7 +486,6 @@ public class TemplateManagerImpl extends TemplateManager implements ProjectCompo } public static boolean isApplicable(PsiFile file, int offset, TemplateImpl template) { - TemplateManager instance = getInstance(file.getProject()); TemplateContext context = template.getTemplateContext(); if (isEnabled(file, offset, null, context)) { return true; diff --git a/resources/src/liveTemplates/surround.xml b/resources/src/liveTemplates/surround.xml index d5232bf4f6e5..07c63bd61572 100644 --- a/resources/src/liveTemplates/surround.xml +++ b/resources/src/liveTemplates/surround.xml @@ -39,7 +39,6 @@