mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-06-23 15:30:45 -04:00
E-book viewer: Fix an error when opening some books with highlights that span inline text formatting
Fixes #1954726 [epub file no longer opens](https://bugs.launchpad.net/calibre/+bug/1954726) [epub file no longer opens](https://bugs.launchpad.net/calibre/+bug/1954726) normalize() modifies the text nodes, and can potentially result in a previously selected node no longer having a parent causing wrap() to throw an exception. In any case normalizing once after all nodes have been wrapped is faster.
This commit is contained in:
parent
27b2f3a92a
commit
07f72d2d94
@ -99,11 +99,6 @@ def wrap_range(r, wrapper):
|
||||
except:
|
||||
wrapper.appendChild(r.extractContents())
|
||||
r.insertNode(wrapper)
|
||||
# remove any empty text nodes created by surroundContents() on either
|
||||
# side of the wrapper. This happens for instance on Chrome when
|
||||
# wrapping all text inside <i>some text</i>
|
||||
r.commonAncestorContainer.normalize()
|
||||
|
||||
|
||||
def create_wrapper_function(wrapper_elem, r, intersecting_wrappers, process_wrapper, all_wrappers):
|
||||
start_node = r.startContainer
|
||||
@ -159,6 +154,10 @@ def wrap_text_in_range(styler, r, class_to_add_to_last, process_wrapper):
|
||||
all_wrappers = v'[]'
|
||||
wrap_node = create_wrapper_function(wrapper_elem, r, intersecting_wrappers, process_wrapper, all_wrappers)
|
||||
text_nodes_in_range(r).map(wrap_node)
|
||||
# remove any empty text nodes created by surroundContents() on either
|
||||
# side of the wrapper. This happens for instance on Chrome when
|
||||
# wrapping all text inside <i>some text</i>
|
||||
r.commonAncestorContainer.normalize()
|
||||
crw = wrapper_elem.dataset.calibreRangeWrapper
|
||||
v'delete intersecting_wrappers[crw]'
|
||||
if class_to_add_to_last and all_wrappers.length:
|
||||
|
Loading…
x
Reference in New Issue
Block a user