From 7d3501404fa699f6aa8849f8979d7be49244548a Mon Sep 17 00:00:00 2001 From: Dmitry Batrak Date: Mon, 1 Jun 2015 15:05:17 +0300 Subject: [PATCH] make End key work properly for RTL text case --- .../editor/actions/EditorActionUtil.java | 11 +++++++--- .../openapi/editor/impl/EditorRtlTest.java | 20 +++++++++++++++++++ .../LightPlatformCodeInsightTestCase.java | 8 ++++++++ 3 files changed, 36 insertions(+), 3 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/actions/EditorActionUtil.java b/platform/platform-impl/src/com/intellij/openapi/editor/actions/EditorActionUtil.java index 4ee4f73cd171..a180c2753d1e 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/actions/EditorActionUtil.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/actions/EditorActionUtil.java @@ -568,7 +568,7 @@ public class EditorActionUtil { } VisualPosition currentVisualCaret = editor.getCaretModel().getVisualPosition(); VisualPosition visualEndOfLineWithCaret - = new VisualPosition(currentVisualCaret.line, EditorUtil.getLastVisualLineColumnNumber(editor, currentVisualCaret.line)); + = new VisualPosition(currentVisualCaret.line, EditorUtil.getLastVisualLineColumnNumber(editor, currentVisualCaret.line), true); // There is a possible case that the caret is already located at the visual end of line and the line is soft wrapped. // We want to move the caret to the end of the next visual line then. @@ -590,7 +590,7 @@ public class EditorActionUtil { line++; column = EditorUtil.getLastVisualLineColumnNumber(editor, line); } - visualEndOfLineWithCaret = new VisualPosition(line, column); + visualEndOfLineWithCaret = new VisualPosition(line, column, true); } } @@ -617,7 +617,12 @@ public class EditorActionUtil { caretModel.moveToVisualPosition(visualEndOfLineWithCaret); } else { - caretModel.moveToOffset(newOffset); + if (editor instanceof EditorImpl && ((EditorImpl)editor).myUseNewRendering) { + caretModel.moveToLogicalPosition(editor.offsetToLogicalPosition(newOffset).leanForward(true)); + } + else { + caretModel.moveToOffset(newOffset); + } } EditorModificationUtil.scrollToCaret(editor); diff --git a/platform/platform-tests/testSrc/com/intellij/openapi/editor/impl/EditorRtlTest.java b/platform/platform-tests/testSrc/com/intellij/openapi/editor/impl/EditorRtlTest.java index 637bf1a2ab94..8ee63be92766 100644 --- a/platform/platform-tests/testSrc/com/intellij/openapi/editor/impl/EditorRtlTest.java +++ b/platform/platform-tests/testSrc/com/intellij/openapi/editor/impl/EditorRtlTest.java @@ -386,6 +386,26 @@ public class EditorRtlTest extends AbstractEditorTest { checkSelection(0, 0); } + public void testHomeEnd() throws Exception { + init("rr"); + myEditor.getCaretModel().moveToOffset(1); + home(); + assertVisualCaretLocation(0, false); + end(); + assertVisualCaretLocation(2, false); + } + + public void testHomeEndWithSelection() throws Exception { + init("rr"); + myEditor.getCaretModel().moveToOffset(1); + homeWithSelection(); + assertVisualCaretLocation(0, false); + checkSelection(0, 1); + endWithSelection(); + assertVisualCaretLocation(2, false); + checkSelection(1, 2); + } + private void init(String text) throws IOException { initText(text.replace(RTL_CHAR_REPRESENTATION, RTL_CHAR)); } diff --git a/platform/testFramework/src/com/intellij/testFramework/LightPlatformCodeInsightTestCase.java b/platform/testFramework/src/com/intellij/testFramework/LightPlatformCodeInsightTestCase.java index 11fc54ceac08..d4d557c3c44a 100644 --- a/platform/testFramework/src/com/intellij/testFramework/LightPlatformCodeInsightTestCase.java +++ b/platform/testFramework/src/com/intellij/testFramework/LightPlatformCodeInsightTestCase.java @@ -518,6 +518,14 @@ public abstract class LightPlatformCodeInsightTestCase extends LightPlatformTest executeAction(IdeActions.ACTION_EDITOR_MOVE_LINE_END); } + protected static void homeWithSelection() { + executeAction(IdeActions.ACTION_EDITOR_MOVE_LINE_START_WITH_SELECTION); + } + + protected static void endWithSelection() { + executeAction(IdeActions.ACTION_EDITOR_MOVE_LINE_END_WITH_SELECTION); + } + protected static void copy() { executeAction(IdeActions.ACTION_EDITOR_COPY); }