This commit is contained in:
Kovid Goyal 2023-04-20 18:09:57 +05:30
parent 7af8910281
commit b92d673ad4
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -28,27 +28,6 @@ def text_nodes_in_range(r):
return ans
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 = is_full_tree
iterator = doc.createNodeIterator(parent)
while True:
node = iterator.nextNode()
if not node:
break
if not in_range and node.isSameNode(r.startContainer):
in_range = True
if in_range:
if node.dataset and node.dataset.calibreRangeWrapper:
annot_id = annot_id_uuid_map[node.dataset.calibreRangeWrapper]
if annot_id:
return annot_id
if not is_full_tree and node.isSameNode(r.endContainer):
break
def all_annots_in_range(r, annot_id_uuid_map, ans):
parent = r.commonAncestorContainer
doc = parent.ownerDocument or document
@ -65,12 +44,18 @@ def all_annots_in_range(r, annot_id_uuid_map, ans):
if node.dataset and node.dataset.calibreRangeWrapper:
annot_id = annot_id_uuid_map[node.dataset.calibreRangeWrapper]
if annot_id:
if not ans:
return annot_id
ans[annot_id] = True
if not is_full_tree and node.isSameNode(r.endContainer):
break
return ans
def first_annot_in_range(r, annot_id_uuid_map):
return all_annots_in_range(r, annot_id_uuid_map)
def all_annots_in_selection(sel, annot_id_uuid_map):
ans = v'{}'
for i in range(sel.rangeCount):