From cae618ac870e89e462cc794a6f664f28945dab06 Mon Sep 17 00:00:00 2001 From: John O'Keefe Date: Sun, 13 Sep 2026 18:30:09 -0400 Subject: [PATCH] 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. --- paginator.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/paginator.js b/paginator.js index 7282663..925ffce 100644 --- a/paginator.js +++ b/paginator.js @@ -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