diff --git a/src/pyj/range_utils.pyj b/src/pyj/range_utils.pyj index 7a070a35dd..7a5200e575 100644 --- a/src/pyj/range_utils.pyj +++ b/src/pyj/range_utils.pyj @@ -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):