Skip to content

Commit 5a72dcf

Browse files
committed
fix getCharacterBoundsOnScreen
Return appropriate bounds when from == to
1 parent dd6aa7f commit 5a72dcf

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

richtextfx/src/main/java/org/fxmisc/richtext/GenericStyledArea.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1037,6 +1037,25 @@ public Optional<Bounds> getCharacterBoundsOnScreen(int from, int to) {
10371037
throw new IllegalArgumentException(String.format("To is greater than area's length. length=%s, to=%s", getLength(), to));
10381038
}
10391039

1040+
if (from == to) {
1041+
CaretNode cursor = new CaretNode( "", this, from );
1042+
int parIdx = offsetToPosition( from, Bias.Forward ).getMajor();
1043+
ParagraphBox<?,?,?> paragrafBox = virtualFlow.getCell( parIdx ).getNode();
1044+
paragrafBox.caretsProperty().add( cursor );
1045+
Bounds cursorBounds = paragrafBox.getCaretBoundsOnScreen( cursor );
1046+
paragrafBox.caretsProperty().remove( cursor );
1047+
1048+
if ( cursorBounds != null && ! cursorBounds.isEmpty() )
1049+
{
1050+
Bounds emptyCharBounds = new BoundingBox(
1051+
cursorBounds.getMinX()+1, cursorBounds.getMinY()+1,
1052+
cursorBounds.getWidth()-1, cursorBounds.getHeight()-2
1053+
);
1054+
return Optional.of( emptyCharBounds );
1055+
}
1056+
return Optional.empty();
1057+
}
1058+
10401059
// no bounds exist if range is just a newline character
10411060
if (getText(from, to).equals("\n")) {
10421061
return Optional.empty();

0 commit comments

Comments
 (0)