incapsulate rtl context determination in Caret instance

This commit is contained in:
Dmitry Batrak
2015-05-28 15:08:43 +03:00
parent 51076c82ad
commit 0dbce46468
5 changed files with 25 additions and 4 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.
@@ -296,4 +296,10 @@ public interface Caret extends UserDataHolderEx, Disposable {
*/
@Nullable
Caret clone(boolean above);
/**
* Returns <code>true</code> if caret is located in RTL text fragment. In that case visual column number is inversely related
* to offset and logical column number in the vicinity of caret.
*/
boolean isAtRtlLocation();
}
@@ -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.
@@ -237,4 +237,9 @@ public class InjectedCaret implements Caret {
public <T> void putUserData(@NotNull Key<T> key, @Nullable T value) {
myDelegate.putUserData(key, value);
}
@Override
public boolean isAtRtlLocation() {
return myDelegate.isAtRtlLocation();
}
}
@@ -1461,6 +1461,11 @@ public class CaretImpl extends UserDataHolderBase implements Caret {
return "Caret at " + myVisibleCaret + (mySelectionMarker == null ? "" : (", selection marker: " + mySelectionMarker.toString()));
}
@Override
public boolean isAtRtlLocation() {
return myEditor.myUseNewRendering && myEditor.myView.isRtlLocation(myOffset, myLogicalCaret.leansForward);
}
/**
* Encapsulates information about target vertical range info - its <code>'y'</code> coordinate and height in pixels.
*/
@@ -4598,7 +4598,7 @@ public final class EditorImpl extends UserDataHolderBase implements EditorEx, Hi
private void setCursorPosition() {
final List<CaretRectangle> caretPoints = new ArrayList<CaretRectangle>();
for (Caret caret : getCaretModel().getAllCarets()) {
boolean isRtl = myUseNewRendering && myView.isRtlLocation(caret.getOffset(), caret.getLogicalPosition().leansForward);
boolean isRtl = caret.isAtRtlLocation();
VisualPosition caretPosition = caret.getVisualPosition();
Point pos1 = visualPositionToXY(caretPosition);
Point pos2 = visualPositionToXY(new VisualPosition(caretPosition.line, Math.max(0, caretPosition.column + (isRtl ? -1 : 1))));
@@ -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.
@@ -198,6 +198,11 @@ public class TextComponentCaret extends UserDataHolderBase implements Caret {
public void dispose() {
}
@Override
public boolean isAtRtlLocation() {
return false;
}
private SelectionModel getSelectionModel() {
return myEditor.getSelectionModel();
}