mirror of
https://github.com/john-okeefe/foliate-js.git
synced 2026-09-30 23:49:10 -04:00
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:
+5
-1
@@ -151,7 +151,11 @@ const getVisibleRange = (doc, start, end, mapRect) => {
|
||||
}
|
||||
|
||||
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.setEnd(sel.focusNode, sel.focusOffset)
|
||||
return range.collapsed
|
||||
|
||||
Reference in New Issue
Block a user