mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
DRYer
This commit is contained in:
parent
7af8910281
commit
b92d673ad4
@ -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):
|
||||
|
Loading…
x
Reference in New Issue
Block a user