From 40ca12ff397157e6acb3bb3d97fa82c5aa6009bc Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 2 Feb 2023 15:33:54 +0530 Subject: [PATCH] Fix detection of selected highlights when all text is selected. See #2003908 (Clear selection when several selections are selected only deletes one) --- src/pyj/range_utils.pyj | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) 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