make 'Move Caret to Text End' action work properly for RTL text case

This commit is contained in:
Dmitry Batrak
2015-06-01 15:41:03 +03:00
parent 7d3501404f
commit fb0c462097
4 changed files with 42 additions and 6 deletions
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2014 JetBrains s.r.o.
* Copyright 2000-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -31,6 +31,10 @@ public interface IdeActions {
@NonNls String ACTION_EDITOR_ENTER = "EditorEnter";
@NonNls String ACTION_EDITOR_START_NEW_LINE = "EditorStartNewLine";
@NonNls String ACTION_EDITOR_SPLIT = "EditorSplitLine";
@NonNls String ACTION_EDITOR_TEXT_START = "EditorTextStart";
@NonNls String ACTION_EDITOR_TEXT_END = "EditorTextEnd";
@NonNls String ACTION_EDITOR_TEXT_START_WITH_SELECTION = "EditorTextStartWithSelection";
@NonNls String ACTION_EDITOR_TEXT_END_WITH_SELECTION = "EditorTextEndWithSelection";
@NonNls String ACTION_EDITOR_MOVE_LINE_START = "EditorLineStart";
@NonNls String ACTION_EDITOR_MOVE_LINE_END = "EditorLineEnd";
@NonNls String ACTION_EDITOR_MOVE_LINE_START_WITH_SELECTION = "EditorLineStartWithSelection";
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2014 JetBrains s.r.o.
* Copyright 2000-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,6 +21,7 @@ import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.editor.ScrollType;
import com.intellij.openapi.editor.ScrollingModel;
import com.intellij.openapi.editor.actionSystem.EditorActionHandler;
import com.intellij.openapi.editor.impl.EditorImpl;
import com.intellij.openapi.fileEditor.ex.IdeDocumentHistory;
import com.intellij.openapi.project.Project;
@@ -38,7 +39,12 @@ public class TextEndAction extends TextComponentEditorAction {
public void execute(Editor editor, DataContext dataContext) {
editor.getCaretModel().removeSecondaryCarets();
int offset = editor.getDocument().getTextLength();
editor.getCaretModel().moveToOffset(offset);
if (editor instanceof EditorImpl && ((EditorImpl)editor).myUseNewRendering) {
editor.getCaretModel().moveToLogicalPosition(editor.offsetToLogicalPosition(offset).leanForward(true));
}
else {
editor.getCaretModel().moveToOffset(offset);
}
editor.getSelectionModel().removeSelection();
ScrollingModel scrollingModel = editor.getScrollingModel();
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2014 JetBrains s.r.o.
* Copyright 2000-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -27,6 +27,7 @@ package com.intellij.openapi.editor.actions;
import com.intellij.openapi.actionSystem.DataContext;
import com.intellij.openapi.editor.*;
import com.intellij.openapi.editor.actionSystem.EditorActionHandler;
import com.intellij.openapi.editor.impl.EditorImpl;
import org.jetbrains.annotations.Nullable;
import java.util.List;
@@ -46,7 +47,7 @@ public class TextEndWithSelectionAction extends TextComponentEditorAction {
caret = carets.get(0) == editor.getCaretModel().getPrimaryCaret() ? carets.get(carets.size() - 1) : carets.get(0);
}
LogicalPosition leadSelectionPosition = editor.visualToLogicalPosition(caret.getLeadSelectionPosition());
LogicalPosition targetPosition = editor.offsetToLogicalPosition(endOffset);
LogicalPosition targetPosition = editor.offsetToLogicalPosition(endOffset).leanForward(true);
editor.getSelectionModel().setBlockSelection(leadSelectionPosition, targetPosition);
}
else {
@@ -54,7 +55,12 @@ public class TextEndWithSelectionAction extends TextComponentEditorAction {
caret = carets.get(0);
}
int selectionStart = caret.getLeadSelectionOffset();
caret.moveToOffset(endOffset);
if (editor instanceof EditorImpl && ((EditorImpl)editor).myUseNewRendering) {
editor.getCaretModel().moveToLogicalPosition(editor.offsetToLogicalPosition(endOffset).leanForward(true));
}
else {
caret.moveToOffset(endOffset);
}
caret.setSelection(selectionStart, endOffset);
}
ScrollingModel scrollingModel = editor.getScrollingModel();
@@ -406,6 +406,26 @@ public class EditorRtlTest extends AbstractEditorTest {
checkSelection(1, 2);
}
public void testTextStartEnd() throws Exception {
init("rr");
myEditor.getCaretModel().moveToOffset(1);
executeAction(IdeActions.ACTION_EDITOR_TEXT_START);
assertVisualCaretLocation(0, false);
executeAction(IdeActions.ACTION_EDITOR_TEXT_END);
assertVisualCaretLocation(2, false);
}
public void testTextStartEndWithSelection() throws Exception {
init("rr");
myEditor.getCaretModel().moveToOffset(1);
executeAction(IdeActions.ACTION_EDITOR_TEXT_START_WITH_SELECTION);
assertVisualCaretLocation(0, false);
checkSelection(0, 1);
executeAction(IdeActions.ACTION_EDITOR_TEXT_END_WITH_SELECTION);
assertVisualCaretLocation(2, false);
checkSelection(1, 2);
}
private void init(String text) throws IOException {
initText(text.replace(RTL_CHAR_REPRESENTATION, RTL_CHAR));
}