diff --git a/src/pyj/range_utils.pyj b/src/pyj/range_utils.pyj index 5f6341cfd6..1217f3db9f 100644 --- a/src/pyj/range_utils.pyj +++ b/src/pyj/range_utils.pyj @@ -31,8 +31,9 @@ def text_nodes_in_range(r): def first_annot_in_range(r, annot_id_uuid_map): parent = r.commonAncestorContainer doc = parent.ownerDocument or document + is_full_tree = parent is doc.documentElement + in_range = not is_full_tree iterator = doc.createNodeIterator(parent) - in_range = False while True: node = iterator.nextNode() if not node: @@ -44,7 +45,7 @@ def first_annot_in_range(r, annot_id_uuid_map): annot_id = annot_id_uuid_map[node.dataset.calibreRangeWrapper] if annot_id: return annot_id - if node.isSameNode(r.endContainer): + if not is_full_tree and node.isSameNode(r.endContainer): break @@ -52,7 +53,8 @@ def all_annots_in_range(r, annot_id_uuid_map, ans): parent = r.commonAncestorContainer doc = parent.ownerDocument or document iterator = doc.createNodeIterator(parent) - in_range = False + is_full_tree = parent is doc.documentElement + in_range = not is_full_tree while True: node = iterator.nextNode() if not node: @@ -64,7 +66,7 @@ def all_annots_in_range(r, annot_id_uuid_map, ans): annot_id = annot_id_uuid_map[node.dataset.calibreRangeWrapper] if annot_id: ans.push(annot_id) - if node.isSameNode(r.endContainer): + if not is_full_tree and node.isSameNode(r.endContainer): break return ans