mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
introduce default offsetToXY/offsetToPoint2D methods in Editor interface
(with more effective implementation in EditorImpl)
This commit is contained in:
@@ -284,6 +284,42 @@ public interface Editor extends UserDataHolder {
|
||||
@NotNull
|
||||
VisualPosition xyToVisualPosition(@NotNull Point2D p);
|
||||
|
||||
/**
|
||||
* @since 2017.2
|
||||
*/
|
||||
@NotNull
|
||||
default Point offsetToXY(int offset) {
|
||||
return offsetToXY(offset, false, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see #offsetToVisualPosition(int, boolean, boolean)
|
||||
* @since 2017.2
|
||||
*/
|
||||
@NotNull
|
||||
default Point offsetToXY(int offset, boolean leanForward, boolean beforeSoftWrap) {
|
||||
VisualPosition visualPosition = offsetToVisualPosition(offset, leanForward, beforeSoftWrap);
|
||||
return visualPositionToXY(visualPosition);
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2017.2
|
||||
*/
|
||||
@NotNull
|
||||
default Point2D offsetToPoint2D(int offset) {
|
||||
return offsetToPoint2D(offset, false, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see #offsetToVisualPosition(int, boolean, boolean)
|
||||
* @since 2017.2
|
||||
*/
|
||||
@NotNull
|
||||
default Point2D offsetToPoint2D(int offset, boolean leanForward, boolean beforeSoftWrap) {
|
||||
VisualPosition visualPosition = offsetToVisualPosition(offset, leanForward, beforeSoftWrap);
|
||||
return visualPositionToPoint2D(visualPosition);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a listener for receiving notifications about mouse clicks in the editor and
|
||||
* the mouse entering/exiting the editor.
|
||||
|
||||
@@ -1250,11 +1250,19 @@ public final class EditorImpl extends UserDataHolderBase implements EditorEx, Hi
|
||||
return myView.xyToVisualPosition(p);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
Point2D offsetToXY(int offset, boolean leanTowardsLargerOffsets) {
|
||||
return myView.offsetToXY(offset, leanTowardsLargerOffsets, false);
|
||||
public Point2D offsetToPoint2D(int offset, boolean leanTowardsLargerOffsets, boolean beforeSoftWrap) {
|
||||
return myView.offsetToXY(offset, leanTowardsLargerOffsets, beforeSoftWrap);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public Point offsetToXY(int offset, boolean leanForward, boolean beforeSoftWrap) {
|
||||
Point2D point2D = offsetToPoint2D(offset, leanForward, beforeSoftWrap);
|
||||
return new Point((int)point2D.getX(), (int)point2D.getY());
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public VisualPosition offsetToVisualPosition(int offset) {
|
||||
|
||||
@@ -144,7 +144,7 @@ class ImmediatePainter {
|
||||
final Font font1 = EditorUtil.fontForChar(c1, attributes1.getFontType(), editor).getFont();
|
||||
final Font font2 = EditorUtil.fontForChar(c1, attributes2.getFontType(), editor).getFont();
|
||||
|
||||
final Point2D p2 = editor.offsetToXY(offset, false);
|
||||
final Point2D p2 = editor.offsetToPoint2D(offset);
|
||||
float p2x = (float)p2.getX();
|
||||
int p2y = (int)p2.getY();
|
||||
int width1i = (int)(p2x) - (int)(p2x - width1);
|
||||
|
||||
+2
-2
@@ -65,8 +65,8 @@ public abstract class AbstractRtlTest extends AbstractEditorTest {
|
||||
visualPositionTowardsLargerOffsets, myEditor.offsetToVisualPosition(offset, true, false));
|
||||
assertEquals("Wrong afterOffset->visualLine calculation",
|
||||
visualPositionTowardsLargerOffsets.line, ((EditorImpl)myEditor).offsetToVisualLine(offset));
|
||||
assertEquals("Wrong beforeOffset->xy calculation", xyTowardsSmallerOffsets, ((EditorImpl)myEditor).offsetToXY(offset, false));
|
||||
assertEquals("Wrong afterOffset->xy calculation", xyTowardsLargerOffsets, ((EditorImpl)myEditor).offsetToXY(offset, true));
|
||||
assertEquals("Wrong beforeOffset->xy calculation", xyTowardsSmallerOffsets, myEditor.offsetToXY(offset, false, false));
|
||||
assertEquals("Wrong afterOffset->xy calculation", xyTowardsLargerOffsets, myEditor.offsetToXY(offset, true, false));
|
||||
}
|
||||
|
||||
protected static void checkLPConversions(int logicalColumn, int offset,
|
||||
|
||||
Reference in New Issue
Block a user