Fix selectionIsBackward for iframe selections

The helper created its probe range in the module's own document
(the host, in the bundled web reader), so boundary points in the
content iframe collapsed the range and every selection read as
backward.
This commit is contained in:
John O'Keefe
2026-09-13 18:30:09 -04:00
parent 2e392e80d3
commit cae618ac87
+5 -1
View File
@@ -151,7 +151,11 @@ const getVisibleRange = (doc, start, end, mapRect) => {
} }
const selectionIsBackward = sel => { const selectionIsBackward = sel => {
const range = document.createRange() // the selection may live in an iframe document while this module runs
// in the host document; create the range in the selection's own
// document or the boundary points cannot be compared
const doc = sel.anchorNode?.ownerDocument ?? document
const range = doc.createRange()
range.setStart(sel.anchorNode, sel.anchorOffset) range.setStart(sel.anchorNode, sel.anchorOffset)
range.setEnd(sel.focusNode, sel.focusOffset) range.setEnd(sel.focusNode, sel.focusOffset)
return range.collapsed return range.collapsed