Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMickael Istria2021-09-13 09:39:55 +0000
committerMickael Istria2021-09-13 11:12:11 +0000
commite0c27e6ed1c36e22b5d75c0ab470ace2d1a6125f (patch)
tree351d7c9d96808878497f5fb83ccea0eda1bd9ebe
parent652af97f3b808f0075cce47268bfd0e544030156 (diff)
downloadeclipse.platform.text-e0c27e6ed1c36e22b5d75c0ab470ace2d1a6125f.tar.gz
eclipse.platform.text-e0c27e6ed1c36e22b5d75c0ab470ace2d1a6125f.tar.xz
eclipse.platform.text-e0c27e6ed1c36e22b5d75c0ab470ace2d1a6125f.zip
Bug 575942 - "Home" & "End" don't work anymore in text editorsI20210913-2050
Change-Id: I7facc9f20f0b66c16983ec1d2d516271af5323b3 Reviewed-on: https://git.eclipse.org/r/c/platform/eclipse.platform.text/+/185367 Tested-by: Platform Bot <platform-bot@eclipse.org> Reviewed-by: Mickael Istria <mistria@redhat.com>
-rw-r--r--org.eclipse.ui.editors.tests/META-INF/MANIFEST.MF3
-rw-r--r--org.eclipse.ui.editors.tests/src/org/eclipse/ui/editors/tests/TextNavigationTest.java37
-rw-r--r--org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/AbstractTextEditor.java7
3 files changed, 39 insertions, 8 deletions
diff --git a/org.eclipse.ui.editors.tests/META-INF/MANIFEST.MF b/org.eclipse.ui.editors.tests/META-INF/MANIFEST.MF
index e6e4c0aba..665d36714 100644
--- a/org.eclipse.ui.editors.tests/META-INF/MANIFEST.MF
+++ b/org.eclipse.ui.editors.tests/META-INF/MANIFEST.MF
@@ -21,7 +21,8 @@ Require-Bundle:
org.eclipse.e4.ui.model.workbench;bundle-version="1.3.0",
org.eclipse.text.tests;bundle-version="[3.5.0,4.0.0)",
org.eclipse.jface.text;bundle-version="3.19.0",
- org.eclipse.ui;bundle-version="3.119.100"
+ org.eclipse.ui;bundle-version="3.119.100",
+ org.eclipse.ui.tests.harness;bundle-version="1.8.0"
Bundle-RequiredExecutionEnvironment: JavaSE-11
Eclipse-BundleShape: dir
Bundle-ActivationPolicy: lazy
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 bbee152b7..b9e3b31d9 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
@@ -11,13 +11,16 @@
package org.eclipse.ui.editors.tests;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
+import java.util.stream.Collectors;
+import java.util.stream.IntStream;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
+import org.junit.After;
+import org.junit.Before;
import org.junit.Test;
import org.eclipse.swt.custom.StyledText;
@@ -29,12 +32,14 @@ import org.eclipse.core.runtime.CoreException;
import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.ITextSelection;
import org.eclipse.jface.text.TextSelection;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.ide.IDE;
+import org.eclipse.ui.tests.harness.util.DisplayHelper;
import org.eclipse.ui.texteditor.AbstractTextEditor;
import org.eclipse.ui.texteditor.ITextEditorActionDefinitionIds;
@@ -49,16 +54,16 @@ public class TextNavigationTest {
private static AbstractTextEditor editor;
private static StyledText widget;
- @BeforeClass
- public static void setUpBeforeClass() throws IOException, PartInitException, CoreException {
+ @Before
+ public void setUpBeforeClass() 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()));
widget = (StyledText) editor.getAdapter(Control.class);
}
- @AfterClass
- public static void tearDownAfterClass() {
+ @After
+ public void tearDown() {
editor.dispose();
file.delete();
}
@@ -89,4 +94,24 @@ public class TextNavigationTest {
assertEquals(5, selection.getLength());
assertEquals(5, widget.getCaretOffset());
}
+
+ @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()));
+ PlatformUI.getWorkbench().getIntroManager().closeIntro(PlatformUI.getWorkbench().getIntroManager().getIntro());
+ assertTrue(DisplayHelper.waitForCondition(widget.getDisplay(), 2000, () -> widget.isVisible()));
+ int firstCharX = widget.getTextBounds(0, 0).x;
+ assertTrue(firstCharX >= 0 && firstCharX <= widget.getClientArea().width);
+ 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;
+ assertTrue(lastCharX >= 0 && lastCharX <= widget.getClientArea().width);
+ editor.getAction(ITextEditorActionDefinitionIds.LINE_START).run();
+ firstCharX = widget.getTextBounds(0, 0).x;
+ assertTrue(firstCharX >= 0 && firstCharX <= widget.getClientArea().width);
+ }
}
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 232b7e401..a245cff5e 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
@@ -1250,6 +1250,9 @@ 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)))
.toArray());
+ if (newSelection.size() == 1) {
+ st.showSelection();
+ }
fireSelectionChanged(firstSelection);
}
}
@@ -1375,7 +1378,9 @@ public abstract class AbstractTextEditor extends EditorPart implements ITextEdit
p -> IntStream.of(Math.max(p.x, p.y), -Math.abs(p.x - p.y))) // negative length to put cursor at
// beginning of selection
.toArray());
-
+ if (newSelection.size() == 1) {
+ st.showSelection();
+ }
fireSelectionChanged(firstSelection);
}
}

Back to the top