Skip to content

Commit 14534d0

Browse files
authored
Accommodate selection when following caret (#933)
1 parent d70a0f4 commit 14534d0

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1698,6 +1698,24 @@ private void followCaret() {
16981698
Bounds caretBounds = cell.getNode().getCaretBounds(caretSelectionBind.getUnderlyingCaret());
16991699
double graphicWidth = cell.getNode().getGraphicPrefWidth();
17001700
Bounds region = extendLeft(caretBounds, graphicWidth);
1701+
double scrollX = virtualFlow.getEstimatedScrollX();
1702+
1703+
// Ordinarily when a caret ends a selection in the target paragraph and scrolling left is required to follow
1704+
// the caret then the selection won't be visible. So here we check for this scenario and adjust if needed.
1705+
if ( ! isWrapText() && scrollX > 0.0 && getParagraphSelection( parIdx ).getLength() > 0 )
1706+
{
1707+
double visibleLeftX = cell.getNode().getWidth() * scrollX / 100 - getWidth() + graphicWidth;
1708+
1709+
CaretNode selectionStart = new CaretNode( "", this, getSelection().getStart() );
1710+
cell.getNode().caretsProperty().add( selectionStart );
1711+
Bounds startBounds = cell.getNode().getCaretBounds( selectionStart );
1712+
cell.getNode().caretsProperty().remove( selectionStart );
1713+
1714+
if ( startBounds.getMinX() - graphicWidth < visibleLeftX ) {
1715+
region = extendLeft( startBounds, graphicWidth );
1716+
}
1717+
}
1718+
17011719
virtualFlow.show(parIdx, region);
17021720
}
17031721

0 commit comments

Comments
 (0)