Skip to content

Commit

Permalink
Improve cursor assoc diagnostic when clicking between lines
Browse files Browse the repository at this point in the history
FIX: Associate a cursor created by clicking above the end of the text on a wrap point
with the line before it.

Closes codemirror/dev#1413
  • Loading branch information
marijnh committed Jul 24, 2024
1 parent 30eb315 commit 2cb2602
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -558,8 +558,7 @@ function rangeForClick(view: EditorView, pos: number, bias: -1 | 1, type: number
}
}

let insideY = (y: number, rect: Rect) => y >= rect.top && y <= rect.bottom
let inside = (x: number, y: number, rect: Rect) => insideY(y, rect) && x >= rect.left && x <= rect.right
let inside = (x: number, y: number, rect: Rect) => y >= rect.top && y <= rect.bottom && x >= rect.left && x <= rect.right

// Try to determine, for the given coordinates, associated with the
// given position, whether they are related to the element before or
Expand All @@ -578,8 +577,8 @@ function findPositionSide(view: EditorView, pos: number, x: number, y: number) {
let after = line.coordsAt(off, 1)
if (after && inside(x, y, after)) return 1
// This is probably a line wrap point. Pick before if the point is
// beside it.
return before && insideY(y, before) ? -1 : 1
// above its bottom.
return before && before.bottom >= y ? -1 : 1
}

function queryPos(view: EditorView, event: MouseEvent): {pos: number, bias: 1 | -1} {
Expand Down

0 comments on commit 2cb2602

Please sign in to comment.