File tree 1 file changed +16
-3
lines changed
richtextfx/src/main/java/org/fxmisc/richtext
1 file changed +16
-3
lines changed Original file line number Diff line number Diff line change @@ -141,23 +141,36 @@ CharacterHit hitLine(double x, int lineIndex) {
141
141
CharacterHit hit (double x , double y ) {
142
142
HitInfo hit = textLayout ().getHitInfo ((float ) x , (float ) y );
143
143
int charIdx = hit .getCharIndex ();
144
+ boolean leading = hit .isLeading ();
144
145
145
146
int lineIdx = getLineIndex ((float ) y );
146
147
if (lineIdx >= getLineCount ()) {
147
148
return CharacterHit .insertionAt (getCharCount ());
148
149
}
149
150
150
- TextLine line = getLines ()[lineIdx ];
151
+ TextLine [] lines = getLines ();
152
+ TextLine line = lines [lineIdx ];
151
153
RectBounds lineBounds = line .getBounds ();
152
154
155
+ // If this is a wrapped paragraph and hit character is at end of hit line,
156
+ // make sure that the "character hit" stays at the end of the hit line
157
+ // (and not at the beginning of the next line).
158
+ if (lines .length > 1 &&
159
+ lineIdx < lines .length - 1 &&
160
+ charIdx + 1 >= line .getStart () + line .getLength () &&
161
+ !leading )
162
+ {
163
+ leading = true ;
164
+ }
165
+
153
166
if (x < lineBounds .getMinX () || x > lineBounds .getMaxX ()) {
154
- if (hit . isLeading () ) {
167
+ if (leading ) {
155
168
return CharacterHit .insertionAt (charIdx );
156
169
} else {
157
170
return CharacterHit .insertionAt (charIdx + 1 );
158
171
}
159
172
} else {
160
- if (hit . isLeading () ) {
173
+ if (leading ) {
161
174
return CharacterHit .leadingHalfOf (charIdx );
162
175
} else {
163
176
return CharacterHit .trailingHalfOf (charIdx );
You can’t perform that action at this time.
0 commit comments