Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMickael Istria2022-02-17 19:50:43 +0000
committerMickael Istria2022-02-18 16:19:54 +0000
commit2ad4b7d7373ac73db2ca7daa24defec9dcc94138 (patch)
treeab8cddbaa3f37684ec91742edb4b68ce7e1e13a9
parentd2b269147d32d23fd862634be8fff8bc65ea23a3 (diff)
downloadeclipse.platform.text-2ad4b7d7373ac73db2ca7daa24defec9dcc94138.tar.gz
eclipse.platform.text-2ad4b7d7373ac73db2ca7daa24defec9dcc94138.tar.xz
eclipse.platform.text-2ad4b7d7373ac73db2ca7daa24defec9dcc94138.zip
"reverse" selections Change-Id: Ie4f6a40a859580aefea2d5b36e36c1790e4b0ecb Reviewed-on: https://git.eclipse.org/r/c/platform/eclipse.platform.text/+/190925 Tested-by: Mickael Istria <mistria@redhat.com> Reviewed-by: Mickael Istria <mistria@redhat.com>
-rw-r--r--org.eclipse.ui.editors.tests/src/org/eclipse/ui/editors/tests/TextNavigationTest.java33
-rw-r--r--org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/AbstractTextEditor.java6
2 files changed, 25 insertions, 14 deletions
diff --git a/org.eclipse.ui.editors.tests/src/org/eclipse/ui/editors/tests/TextNavigationTest.java b/org.eclipse.ui.editors.tests/src/org/eclipse/ui/editors/tests/TextNavigationTest.java
index 2ae93a4c052..0f59a098cb6 100644
--- a/org.eclipse.ui.editors.tests/src/org/eclipse/ui/editors/tests/TextNavigationTest.java
+++ b/org.eclipse.ui.editors.tests/src/org/eclipse/ui/editors/tests/TextNavigationTest.java
@@ -52,15 +52,17 @@ import org.eclipse.ui.texteditor.ITextEditorActionDefinitionIds;
*/
public class TextNavigationTest {
- private static File file;
- private static AbstractTextEditor editor;
- private static StyledText widget;
+ private File file;
+ private AbstractTextEditor editor;
+ private StyledText widget;
+ private IDocument fDocument;
@Before
- public void setUpBeforeClass() throws IOException, PartInitException, CoreException {
+ public void setUp() throws IOException, PartInitException, CoreException {
file = File.createTempFile(TextNavigationTest.class.getName(), ".txt");
Files.write(file.toPath(), " abc".getBytes());
editor = (AbstractTextEditor)IDE.openEditorOnFileStore(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), EFS.getStore(file.toURI()));
+ fDocument = editor.getDocumentProvider().getDocument(editor.getEditorInput());
widget = (StyledText) editor.getAdapter(Control.class);
}
@@ -75,9 +77,8 @@ public class TextNavigationTest {
IPreferenceStore preferenceStore = EditorsPlugin.getDefault().getPreferenceStore();
boolean previousPrefValue = preferenceStore.getBoolean(AbstractTextEditor.PREFERENCE_NAVIGATION_SMART_HOME_END);
preferenceStore.setValue(AbstractTextEditor.PREFERENCE_NAVIGATION_SMART_HOME_END, false);
- IDocument doc = editor.getDocumentProvider().getDocument(editor.getEditorInput());
- doc.set("line1\nline2");
- editor.selectAndReveal(doc.getLength(), 0);
+ fDocument.set("line1\nline2");
+ editor.selectAndReveal(fDocument.getLength(), 0);
editor.getAction(ITextEditorActionDefinitionIds.LINE_START).run();
try {
assertEquals(6, ((ITextSelection) editor.getSelectionProvider().getSelection()).getOffset());
@@ -116,6 +117,17 @@ public class TextNavigationTest {
}
@Test
+ public void testShiftEndMultipleLines() {
+ fDocument.set("LINE 1\nLINE 2\n");
+ editor.selectAndReveal(12, -7);
+ editor.getAction(ITextEditorActionDefinitionIds.SELECT_LINE_END).run();
+ ITextSelection selection = (ITextSelection) editor.getSelectionProvider().getSelection();
+ assertEquals(6, selection.getOffset());
+ assertEquals(6, selection.getLength());
+ assertEquals(6, widget.getCaretOffset());
+ }
+
+ @Test
public void testShiftEndHomeHome() {
editor.getSelectionProvider().setSelection(new TextSelection(0, 0));
assertEquals(0, widget.getCaretOffset());
@@ -142,8 +154,7 @@ public class TextNavigationTest {
@Test
public void testEndHomeRevealCaret() {
editor.getSelectionProvider().setSelection(new TextSelection(0, 0));
- IDocument document = editor.getDocumentProvider().getDocument(editor.getEditorInput());
- document.set(IntStream.range(0, 2000).mapToObj(i -> "a").collect(Collectors.joining()));
+ fDocument.set(IntStream.range(0, 2000).mapToObj(i -> "a").collect(Collectors.joining()));
PlatformUI.getWorkbench().getIntroManager().closeIntro(PlatformUI.getWorkbench().getIntroManager().getIntro());
assertTrue(DisplayHelper.waitForCondition(widget.getDisplay(), 2000, () -> widget.isVisible()));
int firstCharX = widget.getTextBounds(0, 0).x;
@@ -151,8 +162,8 @@ public class TextNavigationTest {
assertEquals(0, widget.getClientArea().x);
editor.getAction(ITextEditorActionDefinitionIds.LINE_END).run();
ITextSelection selection = (ITextSelection) editor.getSelectionProvider().getSelection();
- assertEquals(document.getLength(), selection.getOffset());
- int lastCharX = widget.getTextBounds(document.getLength() - 1, document.getLength() - 1).x;
+ assertEquals(fDocument.getLength(), selection.getOffset());
+ int lastCharX = widget.getTextBounds(fDocument.getLength() - 1, fDocument.getLength() - 1).x;
assertTrue(lastCharX >= 0 && lastCharX <= widget.getClientArea().width);
editor.getAction(ITextEditorActionDefinitionIds.LINE_START).run();
firstCharX = widget.getTextBounds(0, 0).x;
diff --git a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/AbstractTextEditor.java b/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/AbstractTextEditor.java
index 67ef5234995..0cf8f2e6142 100644
--- a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/AbstractTextEditor.java
+++ b/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/AbstractTextEditor.java
@@ -1234,8 +1234,8 @@ public abstract class AbstractTextEditor extends EditorPart implements ITextEdit
int i = getLineEndPosition(document, line, lineLength, caretOffsetInDocument);
newCaretOffset = (caretOffset - lineOffset == i) ? lineEndOffset : lineOffset + i;
} else if (caretOffset < lineEndOffset) {
- // to end of line
- newCaretOffset = lineEndOffset;
+ // to end of line
+ newCaretOffset = lineEndOffset;
}
if (newCaretOffset == -1) {
@@ -1248,7 +1248,7 @@ public abstract class AbstractTextEditor extends EditorPart implements ITextEdit
}
st.setSelectionRanges(newSelection.stream().flatMapToInt(
- p -> IntStream.of(Math.min(p.y, p.x), Math.abs(p.y - p.x)))
+ p -> IntStream.of(p.x, p.y - p.x))
.toArray());
if (newSelection.size() == 1) {
st.showSelection();

Back to the top