From 20aa017ef87be452b01a4685cf2c3007d81418ed Mon Sep 17 00:00:00 2001 From: Alexander Kass Date: Thu, 7 Apr 2016 13:19:51 +0300 Subject: [PATCH] DBE: support surround with function DBE-2534 + ability to keep multicarets --- .../surroundWith/SurroundWithHandler.java | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) 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 61678e49c7c6..bc4326d7c35d 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 @@ -63,6 +63,7 @@ import java.util.*; public class SurroundWithHandler implements CodeInsightActionHandler { private static final Logger LOG = Logger.getInstance("#com.intellij.codeInsight.generation.surroundWith.SurroundWithHandler"); private static final String CHOOSER_TITLE = CodeInsightBundle.message("surround.with.chooser.title"); + public static final TextRange CARET_IS_OK = new TextRange(0, 0); @Override public void invoke(@NotNull final Project project, @NotNull final Editor editor, @NotNull PsiFile file) { @@ -199,16 +200,19 @@ public class SurroundWithHandler implements CodeInsightActionHandler { editor.getCaretModel().moveToLogicalPosition(pos); } TextRange range = surrounder.surroundElements(project, editor, elements); - if (TemplateManager.getInstance(project).getActiveTemplate(editor) == null && InplaceRefactoring.getActiveInplaceRenamer(editor) == null) { - LogicalPosition pos1 = new LogicalPosition(line, col); - editor.getCaretModel().moveToLogicalPosition(pos1); - } - if (range != null) { - int offset = range.getStartOffset(); - editor.getCaretModel().removeSecondaryCarets(); - editor.getCaretModel().moveToOffset(offset); - editor.getScrollingModel().scrollToCaret(ScrollType.RELATIVE); - editor.getSelectionModel().setSelection(range.getStartOffset(), range.getEndOffset()); + if (range != CARET_IS_OK) { + if (TemplateManager.getInstance(project).getActiveTemplate(editor) == null && + InplaceRefactoring.getActiveInplaceRenamer(editor) == null) { + LogicalPosition pos1 = new LogicalPosition(line, col); + editor.getCaretModel().moveToLogicalPosition(pos1); + } + if (range != null) { + int offset = range.getStartOffset(); + editor.getCaretModel().removeSecondaryCarets(); + editor.getCaretModel().moveToOffset(offset); + editor.getScrollingModel().scrollToCaret(ScrollType.RELATIVE); + editor.getSelectionModel().setSelection(range.getStartOffset(), range.getEndOffset()); + } } } catch (IncorrectOperationException e) {