Skip to content

Commit e3f6844

Browse files
authored
Fix for #819 caretBounds graphic bug (#822)
Fix for #812 and #819 caretBounds graphic bug
1 parent 113643f commit e3f6844

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

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

+7-4
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
import javafx.beans.property.ObjectProperty;
2525
import javafx.beans.property.SimpleObjectProperty;
26+
import javafx.beans.value.ChangeListener;
2627
import javafx.collections.FXCollections;
2728
import javafx.collections.MapChangeListener;
2829
import javafx.collections.ObservableMap;
@@ -94,18 +95,19 @@ public ObjectProperty<Paint> highlightTextFillProperty() {
9495
Val<Double> leftInset = Val.map(insetsProperty(), Insets::getLeft);
9596
Val<Double> topInset = Val.map(insetsProperty(), Insets::getTop);
9697

98+
ChangeListener<IndexRange> selectionRangeListener = (obs, ov, nv) -> requestLayout();
9799
selectionPathListener = change -> {
98100
if (change.wasRemoved()) {
99101
SelectionPath p = change.getValueRemoved();
100-
p.rangeProperty().removeListener( (obs, ov, nv) -> requestLayout() );
102+
p.rangeProperty().removeListener(selectionRangeListener);
101103
p.layoutXProperty().unbind();
102104
p.layoutYProperty().unbind();
103105

104106
getChildren().remove(p);
105107
}
106108
if (change.wasAdded()) {
107109
SelectionPath p = change.getValueAdded();
108-
p.rangeProperty().addListener( (obs, ov, nv) -> requestLayout() );
110+
p.rangeProperty().addListener(selectionRangeListener);
109111
p.layoutXProperty().bind(leftInset);
110112
p.layoutYProperty().bind(topInset);
111113

@@ -115,18 +117,19 @@ public ObjectProperty<Paint> highlightTextFillProperty() {
115117
};
116118
selections.addListener( selectionPathListener );
117119

120+
ChangeListener<Integer> caretPositionListener = (obs, ov, nv) -> requestLayout();
118121
caretNodeListener = change -> {
119122
if (change.wasRemoved()) {
120123
CaretNode caret = change.getElementRemoved();
121-
caret.columnPositionProperty().removeListener( (obs, ov, nv) -> requestLayout() );
124+
caret.columnPositionProperty().removeListener(caretPositionListener);
122125
caret.layoutXProperty().unbind();
123126
caret.layoutYProperty().unbind();
124127

125128
getChildren().remove(caret);
126129
}
127130
if (change.wasAdded()) {
128131
CaretNode caret = change.getElementAdded();
129-
caret.columnPositionProperty().addListener( (obs, ov, nv) -> requestLayout() );
132+
caret.columnPositionProperty().addListener(caretPositionListener);
130133
caret.layoutXProperty().bind(leftInset);
131134
caret.layoutYProperty().bind(topInset);
132135

0 commit comments

Comments
 (0)