DBE: support surround with function DBE-2534 + ability to keep multicarets

This commit is contained in:
Alexander Kass
2016-04-07 13:20:57 +03:00
parent 6415c4cd8a
commit 20aa017ef8
@@ -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) {