Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDirk Steinkamp2022-03-17 21:40:25 +0000
committerMickael Istria2022-03-18 13:25:04 +0000
commit070a1ce0eaa11fac3989d37429bdc34854495727 (patch)
treec4f0138d81025fd3d303cdefa51f6ca3c92d46a4
parentbe2ef6867a344a6ed42a235f139ab695bd8e31e8 (diff)
downloadeclipse.platform.text-I20220318-1800.tar.gz
eclipse.platform.text-I20220318-1800.tar.xz
eclipse.platform.text-I20220318-1800.zip
multiselection/multiple carets in text editors Caret-offset now is determined by IMultiTextSelection's regions and thus uses only document-offsets instead of widget offsets, which makes it handle editors e.g. with code folding like the JavaEditor correctly. Change-Id: I6987559dab1cc3e40651e893c22dc3796dcc377a Reviewed-on: https://git.eclipse.org/r/c/platform/eclipse.platform.text/+/192039 Tested-by: Platform Bot <platform-bot@eclipse.org> Reviewed-by: Mickael Istria <mistria@redhat.com>
-rw-r--r--org.eclipse.ui.editors.tests/src/org/eclipse/ui/editors/tests/TextMultiCaretSelectionCommandsTest.java8
-rw-r--r--org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/internal/texteditor/multiselection/AbstractMultiSelectionHandler.java10
-rw-r--r--org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/internal/texteditor/multiselection/StopMultiSelectionHandler.java1
3 files changed, 11 insertions, 8 deletions
diff --git a/org.eclipse.ui.editors.tests/src/org/eclipse/ui/editors/tests/TextMultiCaretSelectionCommandsTest.java b/org.eclipse.ui.editors.tests/src/org/eclipse/ui/editors/tests/TextMultiCaretSelectionCommandsTest.java
index 3165209eb5d..1f700b1672c 100644
--- a/org.eclipse.ui.editors.tests/src/org/eclipse/ui/editors/tests/TextMultiCaretSelectionCommandsTest.java
+++ b/org.eclipse.ui.editors.tests/src/org/eclipse/ui/editors/tests/TextMultiCaretSelectionCommandsTest.java
@@ -381,12 +381,12 @@ public class TextMultiCaretSelectionCommandsTest {
@Test
public void testStopMultiSelection_withMultiSelectionAndCaretAtBeginning_revokesSelectionAndKeepsFirstCaretOffset()
throws Exception {
- setSelection(new IRegion[] { new Region(0, 0), new Region(0, 7), new Region(L1_LEN, 7) });
- assertEquals(0, widget.getCaretOffset());
+ setSelection(new IRegion[] { new Region(0, 7), new Region(L1_LEN, 7) });
+ assertEquals(7, widget.getCaretOffset());
executeCommand(STOP_MULTI_SELECTION);
- assertEquals(0, widget.getCaretOffset());
- assertArrayEquals(new IRegion[] { new Region(0, 0) }, getSelection());
+ assertEquals(7, widget.getCaretOffset());
+ assertArrayEquals(new IRegion[] { new Region(7, 0) }, getSelection());
}
@Test
diff --git a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/internal/texteditor/multiselection/AbstractMultiSelectionHandler.java b/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/internal/texteditor/multiselection/AbstractMultiSelectionHandler.java
index f16c20b8eca..e8f7a40eab1 100644
--- a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/internal/texteditor/multiselection/AbstractMultiSelectionHandler.java
+++ b/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/internal/texteditor/multiselection/AbstractMultiSelectionHandler.java
@@ -221,11 +221,15 @@ abstract class AbstractMultiSelectionHandler extends AbstractHandler {
}
protected int getCaretOffset() {
- return getWidget().getCaretOffset();
+ IRegion[] regions = getSelectedRegions();
+ if (regions == null) {
+ return -1;
+ }
+ return regions[0].getOffset() + regions[0].getLength();
}
- protected void setCaretOffset(int offset) {
- getWidget().setCaretOffset(offset);
+ protected void setCaretOffset(int caretOffset) {
+ selectRegion(offsetAsCaretRegion(caretOffset));
}
protected IRegion findNextMatch(IRegion region) throws ExecutionException {
diff --git a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/internal/texteditor/multiselection/StopMultiSelectionHandler.java b/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/internal/texteditor/multiselection/StopMultiSelectionHandler.java
index 3672da17c69..46a75dcea03 100644
--- a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/internal/texteditor/multiselection/StopMultiSelectionHandler.java
+++ b/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/internal/texteditor/multiselection/StopMultiSelectionHandler.java
@@ -32,7 +32,6 @@ public class StopMultiSelectionHandler extends AbstractMultiSelectionHandler {
private void stopMultiSelection() throws ExecutionException {
int caretOffset = getCaretOffset();
selectRegion(offsetAsCaretRegion(caretOffset));
- setCaretOffset(caretOffset);
setAnchorRegion(null);
}
}

Back to the top