Skip to content

Commit 269bb5e

Browse files
authored
Cleanup caret removal (#1271)
and improve selection removal.
1 parent 740e24c commit 269bb5e

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -456,8 +456,12 @@ public final boolean addCaret(CaretNode caret) {
456456
}
457457

458458
public final boolean removeCaret(CaretNode caret) {
459-
if (caret != caretSelectionBind.getUnderlyingCaret()) {
460-
return caretSet.remove(caret);
459+
if (caret != caretSelectionBind.getUnderlyingCaret() && caretSet.remove(caret)) {
460+
virtualFlow.getCellIfVisible(caret.getParagraphIndex()).ifPresent(
461+
c -> c.getNode().caretsProperty().remove(caret)
462+
);
463+
caret.dispose();
464+
return true;
461465
} else {
462466
return false;
463467
}
@@ -475,7 +479,7 @@ public final boolean addSelection(Selection<PS, SEG, S> selection) {
475479
public final boolean removeSelection(Selection<PS, SEG, S> selection) {
476480
if (selection != caretSelectionBind.getUnderlyingSelection() && selectionSet.remove(selection)) {
477481
for (int p = selection.getStartParagraphIndex(); p <= selection.getEndParagraphIndex(); p++) {
478-
virtualFlow.getCell(p).getNode().selectionsProperty().remove(selection);
482+
virtualFlow.getCellIfVisible(p).ifPresent(c -> c.getNode().selectionsProperty().remove(selection));
479483
}
480484
selection.dispose();
481485
return true;

0 commit comments

Comments
 (0)