Skip to content

Commit 46ed426

Browse files
committed
Fix an issue where domPosAtCoords would fail to scan a child node
FIX: Fix an issue causing coordinates between lines of text to sometimes be inappropriately placed at the end of the line by `posAtCoords`. Issue codemirror/dev#1572
1 parent 92dc051 commit 46ed426

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

src/cursor.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,7 @@ function domPosAtCoords(parent: HTMLElement, x: number, y: number): {node: Node,
7171
return child.nodeType == 3 ? domPosInText(child as Text, x, y) : domPosAtCoords(child as HTMLElement, x, y)
7272
if (!closest || closestY > dy || closestY == dy && closestX > dx) {
7373
closest = child; closestRect = rect; closestX = dx; closestY = dy
74-
let side = dy ? (y < rect.top ? -1 : 1) : dx ? (x < rect.left ? -1 : 1) : 0
75-
closestOverlap = !side || (side > 0 ? i < rects.length - 1 : i > 0)
74+
closestOverlap = !dx ? true : x < rect.left ? i > 0 : i < rects.length - 1
7675
}
7776
if (dx == 0) {
7877
if (y > rect.bottom && (!aboveRect || aboveRect.bottom < rect.bottom)) { above = child; aboveRect = rect }
@@ -236,7 +235,7 @@ function isSuspiciousSafariCaretResult(node: Node, offset: number, x: number) {
236235
scan = parent
237236
}
238237
}
239-
return textRange(node as Text, len - 1, len).getBoundingClientRect().left >= x
238+
return textRange(node as Text, len - 1, len).getBoundingClientRect().right > x
240239
}
241240

242241
// Chrome will move positions between lines to the start of the next line

0 commit comments

Comments
 (0)