Skip to content

Commit

Permalink
Fix for #819 caretBounds graphic bug (#822)
Browse files Browse the repository at this point in the history
Fix for #812 and #819 caretBounds graphic bug
  • Loading branch information
Jugen authored May 20, 2019
1 parent 113643f commit e3f6844
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions richtextfx/src/main/java/org/fxmisc/richtext/ParagraphText.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

import javafx.beans.property.ObjectProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.beans.value.ChangeListener;
import javafx.collections.FXCollections;
import javafx.collections.MapChangeListener;
import javafx.collections.ObservableMap;
Expand Down Expand Up @@ -94,18 +95,19 @@ public ObjectProperty<Paint> highlightTextFillProperty() {
Val<Double> leftInset = Val.map(insetsProperty(), Insets::getLeft);
Val<Double> topInset = Val.map(insetsProperty(), Insets::getTop);

ChangeListener<IndexRange> selectionRangeListener = (obs, ov, nv) -> requestLayout();
selectionPathListener = change -> {
if (change.wasRemoved()) {
SelectionPath p = change.getValueRemoved();
p.rangeProperty().removeListener( (obs, ov, nv) -> requestLayout() );
p.rangeProperty().removeListener(selectionRangeListener);
p.layoutXProperty().unbind();
p.layoutYProperty().unbind();

getChildren().remove(p);
}
if (change.wasAdded()) {
SelectionPath p = change.getValueAdded();
p.rangeProperty().addListener( (obs, ov, nv) -> requestLayout() );
p.rangeProperty().addListener(selectionRangeListener);
p.layoutXProperty().bind(leftInset);
p.layoutYProperty().bind(topInset);

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

ChangeListener<Integer> caretPositionListener = (obs, ov, nv) -> requestLayout();
caretNodeListener = change -> {
if (change.wasRemoved()) {
CaretNode caret = change.getElementRemoved();
caret.columnPositionProperty().removeListener( (obs, ov, nv) -> requestLayout() );
caret.columnPositionProperty().removeListener(caretPositionListener);
caret.layoutXProperty().unbind();
caret.layoutYProperty().unbind();

getChildren().remove(caret);
}
if (change.wasAdded()) {
CaretNode caret = change.getElementAdded();
caret.columnPositionProperty().addListener( (obs, ov, nv) -> requestLayout() );
caret.columnPositionProperty().addListener(caretPositionListener);
caret.layoutXProperty().bind(leftInset);
caret.layoutYProperty().bind(topInset);

Expand Down

0 comments on commit e3f6844

Please sign in to comment.