Skip to content

Commit 6e7f5fe

Browse files
committed
Account for floating point errors in right-to-left test in domPosInText
FIX: Fix an issue where computing a document position from screen coordinates would sometimes go wrong in right-to-left text. See https://discuss.codemirror.net/t/clicking-at-end-of-line-in-rtl-text-places-cursor-at-wrong-location-in-chrome/9571
1 parent 04e446b commit 6e7f5fe

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/cursor.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ function domPosInText(node: Text, x: number, y: number): {node: Node, offset: nu
112112
// Check for RTL on browsers that support getting client
113113
// rects for empty ranges.
114114
let rectBefore = textRange(node, i).getBoundingClientRect()
115-
if (rectBefore.left == rect.right) after = !right
115+
if (Math.abs(rectBefore.left - rect.right) < 0.1) after = !right
116116
}
117117
if (dy <= 0) return {node, offset: i + (after ? 1 : 0)}
118118
closestOffset = i + (after ? 1 : 0)

0 commit comments

Comments
 (0)