From fe84447e6613206f3f2c6f5dee9e218a22f74853 Mon Sep 17 00:00:00 2001 From: Dmitry Batrak Date: Fri, 21 Feb 2014 11:31:59 +0400 Subject: [PATCH] IDEA-80056 Column selection mode improvement small API change, as per review --- .../com/intellij/codeInsight/CodeInsightTestCase.java | 2 +- .../src/com/intellij/codeInsight/EditorInfo.java | 2 +- .../src/com/intellij/openapi/editor/CaretModel.java | 11 +++++------ .../intellij/injected/editor/CaretModelWindow.java | 4 ++-- .../intellij/openapi/editor/impl/CaretModelImpl.java | 2 +- .../openapi/editor/impl/SelectionModelImpl.java | 2 +- .../editor/textarea/TextComponentCaretModel.java | 2 +- .../fileEditor/impl/text/TextEditorProvider.java | 2 +- .../LightPlatformCodeInsightTestCase.java | 2 +- .../fixtures/impl/CodeInsightTestFixtureImpl.java | 2 +- 10 files changed, 15 insertions(+), 16 deletions(-) diff --git a/java/testFramework/src/com/intellij/codeInsight/CodeInsightTestCase.java b/java/testFramework/src/com/intellij/codeInsight/CodeInsightTestCase.java index aecd3d604678..3d386e2b43e7 100644 --- a/java/testFramework/src/com/intellij/codeInsight/CodeInsightTestCase.java +++ b/java/testFramework/src/com/intellij/codeInsight/CodeInsightTestCase.java @@ -442,7 +442,7 @@ public abstract class CodeInsightTestCase extends PsiTestCase { caretPositions.add(pos); selections.add(caret.selection == null ? null : caret.selection); } - editor.getCaretModel().setCarets(caretPositions, selections); + editor.getCaretModel().setCaretsAndSelections(caretPositions, selections); } else { assert caretState.carets.size() == 1 : "Multiple carets are not supported by the model"; diff --git a/java/testFramework/src/com/intellij/codeInsight/EditorInfo.java b/java/testFramework/src/com/intellij/codeInsight/EditorInfo.java index 78d75d673d0a..0ac3e6fe117e 100644 --- a/java/testFramework/src/com/intellij/codeInsight/EditorInfo.java +++ b/java/testFramework/src/com/intellij/codeInsight/EditorInfo.java @@ -65,7 +65,7 @@ public class EditorInfo { caretPositions.add(pos); selections.add(caret.selection == null ? null : caret.selection); } - editor.getCaretModel().setCarets(caretPositions, selections); + editor.getCaretModel().setCaretsAndSelections(caretPositions, selections); } else { assert caretState.carets.size() == 1 : "Multiple carets are not supported by the model"; diff --git a/platform/editor-ui-api/src/com/intellij/openapi/editor/CaretModel.java b/platform/editor-ui-api/src/com/intellij/openapi/editor/CaretModel.java index 776566f900ec..41750a8e1f1c 100644 --- a/platform/editor-ui-api/src/com/intellij/openapi/editor/CaretModel.java +++ b/platform/editor-ui-api/src/com/intellij/openapi/editor/CaretModel.java @@ -22,7 +22,6 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.util.Collection; -import java.util.List; /** * Provides services for moving the caret and retrieving information about caret position. @@ -168,8 +167,8 @@ public interface CaretModel { /** * Returns current caret - the one, query and update methods in the model operate at the moment. In the current implementation this is - * either an iteration-current caret within the context of {@link #runForEachCaret(Runnable)} method, or the 'primary' caret without that - * context. Users {@link #runForEachCaret(Runnable)} method should use caret parameter passed to + * either an iteration-current caret within the context of {@link #runForEachCaret(CaretAction)} method, or the 'primary' caret without that + * context. Users {@link #runForEachCaret(CaretAction)} method should use caret parameter passed to * {@link com.intellij.openapi.editor.CaretAction#perform(Caret)} method instead of this method, as the definition of current caret (as * well as caret instance operated on by model methods) can potentially change. */ @@ -215,14 +214,14 @@ public interface CaretModel { void removeSecondaryCarets(); /** - * Sets the number of carets, their positions and selection ranges according to the provided parameters. Null values in any of the lists - * will mean that corresponding caret's position and/or selection won't be changed. + * Sets the number of carets, their positions and selection ranges according to the provided parameters. Null values in any of the + * collections will mean that corresponding caret's position and/or selection won't be changed. *

* If multiple carets are not supported, the behaviour is unspecified. * * @see #supportsMultipleCarets() */ - void setCarets(@NotNull List caretPositions, @NotNull List selections); + void setCaretsAndSelections(@NotNull Collection caretPositions, @NotNull Collection selections); /** * Executes the given task for each existing caret. Carets are iterated in their position order. Set of carets to iterate over is diff --git a/platform/lang-impl/src/com/intellij/injected/editor/CaretModelWindow.java b/platform/lang-impl/src/com/intellij/injected/editor/CaretModelWindow.java index a3e4a80aa756..bdaa6bd6734c 100644 --- a/platform/lang-impl/src/com/intellij/injected/editor/CaretModelWindow.java +++ b/platform/lang-impl/src/com/intellij/injected/editor/CaretModelWindow.java @@ -205,7 +205,7 @@ public class CaretModelWindow implements CaretModel { } @Override - public void setCarets(@NotNull List caretPositions, @NotNull List selections) { + public void setCaretsAndSelections(@NotNull Collection caretPositions, @NotNull Collection selections) { List convertedPositions = new ArrayList(caretPositions); for (LogicalPosition position : caretPositions) { convertedPositions.add(myEditorWindow.injectedToHost(position)); @@ -215,7 +215,7 @@ public class CaretModelWindow implements CaretModel { convertedSelections.add(new TextRange(myEditorWindow.getDocument().injectedToHost(selection.getStartOffset()), myEditorWindow.getDocument().injectedToHost(selection.getEndOffset()))); } - myDelegate.setCarets(convertedPositions, convertedSelections); + myDelegate.setCaretsAndSelections(convertedPositions, convertedSelections); } private InjectedCaret createInjectedCaret(Caret caret) { diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/impl/CaretModelImpl.java b/platform/platform-impl/src/com/intellij/openapi/editor/impl/CaretModelImpl.java index cb0aee733817..0603100696a9 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/impl/CaretModelImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/impl/CaretModelImpl.java @@ -452,7 +452,7 @@ public class CaretModelImpl implements CaretModel, PrioritizedDocumentListener, } @Override - public void setCarets(@NotNull final List caretPositions, @NotNull final List selections) { + public void setCaretsAndSelections(@NotNull final Collection caretPositions, @NotNull final Collection selections) { myEditor.assertIsDispatchThread(); if (caretPositions.isEmpty()) { throw new IllegalArgumentException("At least one caret should exist"); diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/impl/SelectionModelImpl.java b/platform/platform-impl/src/com/intellij/openapi/editor/impl/SelectionModelImpl.java index 90780f19bf46..46be8b85a5cf 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/impl/SelectionModelImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/impl/SelectionModelImpl.java @@ -249,7 +249,7 @@ public class SelectionModelImpl implements SelectionModel, PrioritizedDocumentLi } } } - myEditor.getCaretModel().setCarets(positions, selections); + myEditor.getCaretModel().setCaretsAndSelections(positions, selections); } else { removeSelection(); diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/textarea/TextComponentCaretModel.java b/platform/platform-impl/src/com/intellij/openapi/editor/textarea/TextComponentCaretModel.java index 32e8f3b66592..ec8c6693b265 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/textarea/TextComponentCaretModel.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/textarea/TextComponentCaretModel.java @@ -180,7 +180,7 @@ public class TextComponentCaretModel implements CaretModel { } @Override - public void setCarets(@NotNull List caretPositions, @NotNull List selections) { + public void setCaretsAndSelections(@NotNull Collection caretPositions, @NotNull Collection selections) { throw new UnsupportedOperationException("Multiple carets are not supported"); } diff --git a/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/text/TextEditorProvider.java b/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/text/TextEditorProvider.java index e07a85cfbc38..4514ee8fbe58 100644 --- a/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/text/TextEditorProvider.java +++ b/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/text/TextEditorProvider.java @@ -252,7 +252,7 @@ public class TextEditorProvider implements FileEditorProvider, DumbAware { positions.add(new LogicalPosition(caretState.LINE, caretState.COLUMN)); selections.add(new TextRange(caretState.SELECTION_START, caretState.SELECTION_END)); } - caretModel.setCarets(positions, selections); + caretModel.setCaretsAndSelections(positions, selections); } else { LogicalPosition pos = new LogicalPosition(state.CARETS[0].LINE, state.CARETS[0].COLUMN); editor.getCaretModel().moveToLogicalPosition(pos); diff --git a/platform/testFramework/src/com/intellij/testFramework/LightPlatformCodeInsightTestCase.java b/platform/testFramework/src/com/intellij/testFramework/LightPlatformCodeInsightTestCase.java index e0e8e3d2b656..3c6911e18dca 100644 --- a/platform/testFramework/src/com/intellij/testFramework/LightPlatformCodeInsightTestCase.java +++ b/platform/testFramework/src/com/intellij/testFramework/LightPlatformCodeInsightTestCase.java @@ -209,7 +209,7 @@ public abstract class LightPlatformCodeInsightTestCase extends LightPlatformTest caretPositions.add(pos); selections.add(caret.selection == null ? null : caret.selection); } - myEditor.getCaretModel().setCarets(caretPositions, selections); + myEditor.getCaretModel().setCaretsAndSelections(caretPositions, selections); } else { assertEquals("Caret model doesn't support multiple carets", 1, carets.size()); diff --git a/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/CodeInsightTestFixtureImpl.java b/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/CodeInsightTestFixtureImpl.java index 82a3ad68c25e..1559e8bafe02 100644 --- a/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/CodeInsightTestFixtureImpl.java +++ b/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/CodeInsightTestFixtureImpl.java @@ -1367,7 +1367,7 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig caretPositions.add(caret.offset == null ? null : myEditor.offsetToLogicalPosition(caret.offset)); selections.add(caret.selection == null ? null : caret.selection); } - myEditor.getCaretModel().setCarets(caretPositions, selections); + myEditor.getCaretModel().setCaretsAndSelections(caretPositions, selections); } else { assert loader.caretState.carets.size() == 1 : "Multiple carets are not supported by the model";