mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-80056 Column selection mode improvement
added some tests for multi-caret state, copying existing block selection tests Updated SurroundWithHandler to work more properly in multi-caret state
This commit is contained in:
+6
-3
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
* Copyright 2000-2014 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -192,8 +192,10 @@ public class SurroundWithHandler implements CodeInsightActionHandler {
|
||||
PsiDocumentManager.getInstance(project).commitAllDocuments();
|
||||
int col = editor.getCaretModel().getLogicalPosition().column;
|
||||
int line = editor.getCaretModel().getLogicalPosition().line;
|
||||
LogicalPosition pos = new LogicalPosition(0, 0);
|
||||
editor.getCaretModel().moveToLogicalPosition(pos);
|
||||
if (!editor.getCaretModel().supportsMultipleCarets()) {
|
||||
LogicalPosition pos = new LogicalPosition(0, 0);
|
||||
editor.getCaretModel().moveToLogicalPosition(pos);
|
||||
}
|
||||
TextRange range = surrounder.surroundElements(project, editor, elements);
|
||||
if (TemplateManager.getInstance(project).getActiveTemplate(editor) == null) {
|
||||
LogicalPosition pos1 = new LogicalPosition(line, col);
|
||||
@@ -201,6 +203,7 @@ public class SurroundWithHandler implements CodeInsightActionHandler {
|
||||
}
|
||||
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());
|
||||
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright 2000-2014 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.openapi.editor.actions
|
||||
|
||||
import com.intellij.testFramework.EditorTestUtil
|
||||
|
||||
class MultiCaretBlockSelectionTest extends BlockSelectionTest {
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp()
|
||||
EditorTestUtil.enableMultipleCarets()
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
EditorTestUtil.disableMultipleCarets()
|
||||
super.tearDown()
|
||||
}
|
||||
}
|
||||
+12
-1
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2013 JetBrains s.r.o.
|
||||
* Copyright 2000-2014 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -204,4 +204,15 @@ public abstract class AbstractEditorTest extends LightPlatformCodeInsightTestCas
|
||||
mapper.rawAdd(visualLine, startOffset, endOffset, startLogicalLine, startLogicalColumn, endLogicalLine, endLogicalColumn, endVisualColumn, foldRegions, tabData);
|
||||
}
|
||||
}
|
||||
|
||||
public void assertSelectionRanges(int[][] ranges) {
|
||||
int[] selectionStarts = myEditor.getSelectionModel().getBlockSelectionStarts();
|
||||
int[] selectionEnds = myEditor.getSelectionModel().getBlockSelectionEnds();
|
||||
int actualRangeCount = selectionStarts.length;
|
||||
int[][] actualRanges = new int[actualRangeCount][];
|
||||
for (int i = 0; i < actualRangeCount; i++) {
|
||||
actualRanges[i] = new int[] {selectionStarts[i], selectionEnds[i]};
|
||||
}
|
||||
assertEquals("Wrong selected ranges", Arrays.deepToString(ranges), Arrays.deepToString(actualRanges));
|
||||
}
|
||||
}
|
||||
|
||||
+12
-1
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2013 JetBrains s.r.o.
|
||||
* Copyright 2000-2014 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -17,6 +17,7 @@ package com.intellij.openapi.editor.impl;
|
||||
|
||||
import com.intellij.openapi.editor.ex.EditorEx;
|
||||
import com.intellij.openapi.fileTypes.PlainTextFileType;
|
||||
import com.intellij.testFramework.EditorTestUtil;
|
||||
import com.intellij.testFramework.fixtures.LightPlatformCodeInsightFixtureTestCase;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.junit.Assert;
|
||||
@@ -38,6 +39,16 @@ public class IterationStateTest extends LightPlatformCodeInsightFixtureTestCase
|
||||
new Segment(10, 11, Color.BLACK));
|
||||
}
|
||||
|
||||
public void testMultiCaretBlockSelection() {
|
||||
EditorTestUtil.enableMultipleCarets();
|
||||
try {
|
||||
testBlockSelection();
|
||||
}
|
||||
finally {
|
||||
EditorTestUtil.disableMultipleCarets();
|
||||
}
|
||||
}
|
||||
|
||||
private void verifySplitting(String text, Segment... expectedSegments) {
|
||||
myFixture.configureByText(PlainTextFileType.INSTANCE, text);
|
||||
EditorEx editor = (EditorEx)myFixture.getEditor();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2013 JetBrains s.r.o.
|
||||
* Copyright 2000-2014 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -26,6 +26,7 @@ import com.intellij.openapi.editor.highlighter.HighlighterIterator;
|
||||
import com.intellij.openapi.editor.impl.DefaultEditorTextRepresentationHelper;
|
||||
import com.intellij.openapi.editor.impl.SoftWrapModelImpl;
|
||||
import com.intellij.openapi.editor.impl.softwrap.mapping.SoftWrapApplianceManager;
|
||||
import com.intellij.openapi.util.registry.Registry;
|
||||
import com.intellij.psi.tree.IElementType;
|
||||
import junit.framework.Assert;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -173,4 +174,12 @@ public class EditorTestUtil {
|
||||
applianceManager.registerSoftWrapIfNecessary();
|
||||
return !model.getRegisteredSoftWraps().isEmpty();
|
||||
}
|
||||
|
||||
public static void enableMultipleCarets() {
|
||||
Registry.get("editor.allow.multiple.carets").setValue(true);
|
||||
}
|
||||
|
||||
public static void disableMultipleCarets() {
|
||||
Registry.get("editor.allow.multiple.carets").setValue(false);
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2013 JetBrains s.r.o.
|
||||
* Copyright 2000-2014 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -624,7 +624,7 @@ public abstract class LightPlatformCodeInsightTestCase extends LightPlatformTest
|
||||
public void run() {
|
||||
EditorActionManager actionManager = EditorActionManager.getInstance();
|
||||
EditorActionHandler actionHandler = actionManager.getActionHandler(actionId);
|
||||
actionHandler.execute(getEditor(), DataManager.getInstance().getDataContext());
|
||||
actionHandler.executeForAllCarets(getEditor(), DataManager.getInstance().getDataContext());
|
||||
}
|
||||
}, "", null);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user