E-book viewer: Fix modifying an existing highlight causing duplicates to be created in some books. Fixes #2122747 [Private bug](https://bugs.launchpad.net/calibre/+bug/2122747)

Probably the issue manifests when using box-sizing: border-box in the
book CSS, but I didnt bother to check for the exact cause.
This commit is contained in:
Kovid Goyal 2025-09-15 11:13:45 +05:30
parent 81475dad84
commit d346c19c80
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -32,6 +32,7 @@ def select_nodes_from_range(r, predicate):
iterator = doc.createNodeIterator(parent)
in_range = False
ans = v'[]'
check_for_end = not (r.startContainer.isSameNode(r.endContainer) and r.startContainer.isSameNode(parent))
while True:
node = iterator.nextNode()
if not node:
@ -41,7 +42,7 @@ def select_nodes_from_range(r, predicate):
if in_range:
if predicate(node):
ans.push(node)
if node.isSameNode(r.endContainer):
if check_for_end and node.isSameNode(r.endContainer):
break
return ans
@ -51,6 +52,7 @@ def select_first_node_from_range(r, predicate):
doc = parent.ownerDocument or document
iterator = doc.createNodeIterator(parent)
in_range = False
check_for_end = not (r.startContainer.isSameNode(r.endContainer) and r.startContainer.isSameNode(parent))
while True:
node = iterator.nextNode()
if not node:
@ -60,7 +62,7 @@ def select_first_node_from_range(r, predicate):
if in_range:
if predicate(node):
return node
if node.isSameNode(r.endContainer):
if check_for_end and node.isSameNode(r.endContainer):
break
@ -74,6 +76,7 @@ def all_annots_in_range(r, annot_id_uuid_map, ans):
iterator = doc.createNodeIterator(parent)
is_full_tree = parent is doc.documentElement
in_range = is_full_tree
check_for_end = not is_full_tree and not (r.startContainer.isSameNode(r.endContainer) and r.startContainer.isSameNode(parent))
while True:
node = iterator.nextNode()
if not node:
@ -87,7 +90,7 @@ def all_annots_in_range(r, annot_id_uuid_map, ans):
if not ans:
return annot_id
ans[annot_id] = True
if not is_full_tree and node.isSameNode(r.endContainer):
if check_for_end and node.isSameNode(r.endContainer):
break
return ans