Skip to content

Commit 76e252d

Browse files
committed
Add kludge to improve handling of clicks after line wrapping breaks
Issue codemirror#4078
1 parent 3aba5a8 commit 76e252d

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

lib/codemirror.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2933,10 +2933,23 @@
29332933
for (;;) {
29342934
if (bidi ? to == from || to == moveVisually(lineObj, from, 1) : to - from <= 1) {
29352935
var ch = x < fromX || x - fromX <= toX - x ? from : to;
2936+
var outside = ch == from ? fromOutside : toOutside
29362937
var xDiff = x - (ch == from ? fromX : toX);
2938+
// This is a kludge to handle the case where the coordinates
2939+
// are after a line-wrapped line. We should replace it with a
2940+
// more general handling of cursor positions around line
2941+
// breaks. (Issue #4078)
2942+
if (toOutside && !bidi && !/\s/.test(lineObj.text.charAt(ch)) && xDiff > 0 &&
2943+
ch < lineObj.text.length && preparedMeasure.view.measure.heights.length > 1) {
2944+
var charSize = measureCharPrepared(cm, preparedMeasure, ch, "right");
2945+
if (innerOff <= charSize.bottom && innerOff >= charSize.top && Math.abs(x - charSize.right) < xDiff) {
2946+
outside = false
2947+
ch++
2948+
xDiff = x - charSize.right
2949+
}
2950+
}
29372951
while (isExtendingChar(lineObj.text.charAt(ch))) ++ch;
2938-
var pos = PosWithInfo(lineNo, ch, ch == from ? fromOutside : toOutside,
2939-
xDiff < -1 ? -1 : xDiff > 1 ? 1 : 0);
2952+
var pos = PosWithInfo(lineNo, ch, outside, xDiff < -1 ? -1 : xDiff > 1 ? 1 : 0);
29402953
return pos;
29412954
}
29422955
var step = Math.ceil(dist / 2), middle = from + step;

0 commit comments

Comments
 (0)