Skip to content

Commit 92dc051

Browse files
committed
Further improve Safari caretRangeFromPoint correction
Issue codemirror/dev#1572
1 parent 32a5d55 commit 92dc051

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/cursor.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -223,10 +223,19 @@ function posAtCoordsImprecise(view: EditorView, contentRect: Rect, block: BlockI
223223
// line before. This is used to detect such a result so that it can be
224224
// ignored (issue #401).
225225
function isSuspiciousSafariCaretResult(node: Node, offset: number, x: number) {
226-
let len
226+
let len, scan = node
227227
if (node.nodeType != 3 || offset != (len = node.nodeValue!.length)) return false
228-
for (let next = node.nextSibling; next; next = next.nextSibling)
229-
if (next.nodeType != 1 || next.nodeName != "BR") return false
228+
for (;;) { // Check that there is no content after this node
229+
let next = scan.nextSibling
230+
if (next) {
231+
if (next.nodeName == "BR") break
232+
return false
233+
} else {
234+
let parent = scan.parentNode
235+
if (!parent || parent.nodeName == "DIV") break
236+
scan = parent
237+
}
238+
}
230239
return textRange(node as Text, len - 1, len).getBoundingClientRect().left >= x
231240
}
232241

0 commit comments

Comments
 (0)