Skip to content

Commit

Permalink
Add kludge to improve handling of clicks after line wrapping breaks
Browse files Browse the repository at this point in the history
  • Loading branch information
marijnh committed Jun 20, 2016
1 parent 3aba5a8 commit 76e252d
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions lib/codemirror.js
Original file line number Diff line number Diff line change
Expand Up @@ -2933,10 +2933,23 @@
for (;;) {
if (bidi ? to == from || to == moveVisually(lineObj, from, 1) : to - from <= 1) {
var ch = x < fromX || x - fromX <= toX - x ? from : to;
var outside = ch == from ? fromOutside : toOutside
var xDiff = x - (ch == from ? fromX : toX);
// This is a kludge to handle the case where the coordinates
// are after a line-wrapped line. We should replace it with a
// more general handling of cursor positions around line
// breaks. (Issue #4078)
if (toOutside && !bidi && !/\s/.test(lineObj.text.charAt(ch)) && xDiff > 0 &&
ch < lineObj.text.length && preparedMeasure.view.measure.heights.length > 1) {
var charSize = measureCharPrepared(cm, preparedMeasure, ch, "right");
if (innerOff <= charSize.bottom && innerOff >= charSize.top && Math.abs(x - charSize.right) < xDiff) {
outside = false
ch++
xDiff = x - charSize.right
}
}
while (isExtendingChar(lineObj.text.charAt(ch))) ++ch;
var pos = PosWithInfo(lineNo, ch, ch == from ? fromOutside : toOutside,
xDiff < -1 ? -1 : xDiff > 1 ? 1 : 0);
var pos = PosWithInfo(lineNo, ch, outside, xDiff < -1 ? -1 : xDiff > 1 ? 1 : 0);
return pos;
}
var step = Math.ceil(dist / 2), middle = from + step;
Expand Down

0 comments on commit 76e252d

Please sign in to comment.