Skip to content

Commit f97fff8

Browse files
committed
adjust wrapped lines selection to the rest of the line (similar to FXMisc#549 / FXMisc#564)
also closing rectangle path in createRectangle()
1 parent 09b58a3 commit f97fff8

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

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

+15-1
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,19 @@ private PathElement[] getRangeShapeSafely(int start, int end) {
294294
shape[bottomRightIndex] = new LineTo(getWidth(), getHeight());
295295
}
296296
}
297+
298+
if (getLineCount() > 1) {
299+
// adjust right corners of wrapped lines
300+
boolean wrappedAtEndPos = (end > 0 && getLineOfCharacter(end) > getLineOfCharacter(end - 1));
301+
int adjustLength = shape.length - (wrappedAtEndPos ? 0 : 5);
302+
for (int i = 0; i < adjustLength; i++) {
303+
if (shape[i] instanceof MoveTo) {
304+
((LineTo)shape[i + 1]).setX(getWidth());
305+
((LineTo)shape[i + 2]).setX(getWidth());
306+
}
307+
}
308+
}
309+
297310
return shape;
298311
}
299312

@@ -302,7 +315,8 @@ private PathElement[] createRectangle(double topLeftX, double topLeftY, double b
302315
new MoveTo(topLeftX, topLeftY),
303316
new LineTo(bottomRightX, topLeftY),
304317
new LineTo(bottomRightX, bottomRightY),
305-
new LineTo(topLeftX, bottomRightY)
318+
new LineTo(topLeftX, bottomRightY),
319+
new LineTo(topLeftX, topLeftY)
306320
};
307321
}
308322

0 commit comments

Comments
 (0)