Viewer: Fix error when scrolling to some search results in flow mode. Fixes #1908000 [calibre viewer shows "Unhandled error: Uncaught InvalidStateError: Failed to execute 'surroundContents' on 'Range'" after RegExp searching in epub-file](https://bugs.launchpad.net/calibre/+bug/1908000)

This commit is contained in:
Kovid Goyal 2020-12-21 11:27:16 +05:30
parent 26998b0a59
commit 47b4530a56
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -94,7 +94,11 @@ def select_crw(crw):
def wrap_range(r, wrapper):
r.surroundContents(wrapper)
try:
r.surroundContents(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>