Viewer: Fix rare exception when navigating to a CFI. Fixes #1849775 [Exception in ebook viewer](https://bugs.launchpad.net/calibre/+bug/1849775)

This commit is contained in:
Kovid Goyal 2019-10-25 20:37:01 +05:30
parent 89eef411c4
commit 99ce8f9876
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -540,12 +540,22 @@ def scroll_to(cfi, callback, doc): # {{{
p.normalize()
# Reset the range to what it was before the span was added
r.setStart(sc, so)
try:
r.setEnd(ec, eo)
except:
# this happens for some japanese books
r.setEnd(ec, eo-1)
offset = so
while offset > -1:
try:
r.setStart(sc, offset)
break
except:
offset -= 1
offset = eo
while offset > -1:
try:
r.setEnd(ec, offset)
break
except:
offset -= 1
rects = r.getClientRects()
if rects.length > 0:
rect = rects[0]