Fix detection of selected highlights when all text is selected. See #2003908 (Clear selection when several selections are selected only deletes one)

This commit is contained in:
Kovid Goyal 2023-02-02 15:33:54 +05:30
parent be4e875706
commit 40ca12ff39
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -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