Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMickael Istria2021-11-18 18:55:09 +0000
committerMickael Istria2021-11-19 10:32:19 +0000
commit6ff1319e90cb6e78b3d6a79696f1ec4b121a1a72 (patch)
tree995412eb2b8cd4999f902c075bc0460606597a5e
parent9c53fe96ecfc979b55e428ad8eae8cd5733ae586 (diff)
downloadeclipse.platform.text-6ff1319e90cb6e78b3d6a79696f1ec4b121a1a72.tar.gz
eclipse.platform.text-6ff1319e90cb6e78b3d6a79696f1ec4b121a1a72.tar.xz
eclipse.platform.text-6ff1319e90cb6e78b3d6a79696f1ec4b121a1a72.zip
Change-Id: I91152d94d540eeb00ec400618af18a623d67a748 Reviewed-on: https://git.eclipse.org/r/c/platform/eclipse.platform.text/+/187903 Tested-by: Platform Bot <platform-bot@eclipse.org> Reviewed-by: Sebastian Ratz <sebastian.ratz@sap.com> Reviewed-by: Mickael Istria <mistria@redhat.com>
-rw-r--r--org.eclipse.ui.editors.tests/src/org/eclipse/ui/editors/tests/TextNavigationTest.java20
-rw-r--r--org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/AbstractTextEditor.java2
2 files changed, 21 insertions, 1 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 b9e3b31d9cc..9449786fdd7 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
@@ -31,6 +31,7 @@ import org.eclipse.core.filesystem.EFS;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.ITextSelection;
@@ -39,6 +40,7 @@ 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.internal.editors.text.EditorsPlugin;
import org.eclipse.ui.tests.harness.util.DisplayHelper;
import org.eclipse.ui.texteditor.AbstractTextEditor;
@@ -69,6 +71,24 @@ public class TextNavigationTest {
}
@Test
+ public void testHome() {
+ 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);
+ editor.getAction(ITextEditorActionDefinitionIds.LINE_START).run();
+ try {
+ assertEquals(6, ((ITextSelection) editor.getSelectionProvider().getSelection()).getOffset());
+ editor.getAction(ITextEditorActionDefinitionIds.LINE_START).run();
+ assertEquals(6, ((ITextSelection) editor.getSelectionProvider().getSelection()).getOffset());
+ } finally {
+ preferenceStore.setValue(AbstractTextEditor.PREFERENCE_NAVIGATION_SMART_HOME_END, previousPrefValue);
+ }
+ }
+
+ @Test
public void testShiftHome() {
editor.selectAndReveal(5, 0);
IAction action= editor.getAction(ITextEditorActionDefinitionIds.SELECT_LINE_START);
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 b8a57d389e0..29fc5c401f4 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
@@ -1362,7 +1362,7 @@ public abstract class AbstractTextEditor extends EditorPart implements ITextEdit
// Compute the line start offset
int index = getLineStartPosition(document, line, lineLength, caretOffsetInDocument);
newCaretOffset = (caretOffset - lineOffset == index) ? lineOffset : lineOffset + index;
- } else if (caretOffset > lineOffset) {
+ } else if (caretOffset >= lineOffset) {
// to beginning of line
newCaretOffset = lineOffset;
}

Back to the top