From 944a701fc221729ac8e6537a866a49df713a2296 Mon Sep 17 00:00:00 2001 From: Neil Brown Date: Fri, 5 May 2017 12:40:14 +0100 Subject: [PATCH] Fixes issue #499: calling getCharacterBoundsOnScreen on a paragraph with selection stops the selection being displayed. The getCharacterBoundsOnScreen method borrows the selectionShape to do the calculation, but it was only taking a reference to the list beforehand, so the saved "copy" was getting wiped out and thus not restoring the selection properly afterwards. Simple fix: take copy of the list, not a reference. --- .../src/main/java/org/fxmisc/richtext/ParagraphText.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/richtextfx/src/main/java/org/fxmisc/richtext/ParagraphText.java b/richtextfx/src/main/java/org/fxmisc/richtext/ParagraphText.java index fe2647194..ac689a70b 100644 --- a/richtextfx/src/main/java/org/fxmisc/richtext/ParagraphText.java +++ b/richtextfx/src/main/java/org/fxmisc/richtext/ParagraphText.java @@ -156,7 +156,8 @@ public Bounds getRangeBoundsOnScreen(int from, int to) { PathElement[] rangeShape = getRangeShape(from, to); // switch out shapes to calculate the bounds on screen - List selShape = selectionShape.getElements(); + // Must take a copy of the list contents, not just a reference: + List selShape = new ArrayList<>(selectionShape.getElements()); selectionShape.getElements().setAll(rangeShape); Bounds localBounds = selectionShape.getBoundsInLocal(); Bounds rangeBoundsOnScreen = selectionShape.localToScreen(localBounds);