From 2cb26028cc5a01dc474a45426e4bc661c721db8d Mon Sep 17 00:00:00 2001 From: Marijn Haverbeke Date: Wed, 24 Jul 2024 21:53:45 +0200 Subject: [PATCH] Improve cursor assoc diagnostic when clicking between lines FIX: Associate a cursor created by clicking above the end of the text on a wrap point with the line before it. Closes https://github.com/codemirror/dev/issues/1413 --- src/input.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/input.ts b/src/input.ts index 2734be6..8f49843 100644 --- a/src/input.ts +++ b/src/input.ts @@ -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 @@ -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} {