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() p.normalize()
# Reset the range to what it was before the span was added # Reset the range to what it was before the span was added
r.setStart(sc, so) offset = so
while offset > -1:
try: try:
r.setEnd(ec, eo) r.setStart(sc, offset)
break
except: except:
# this happens for some japanese books offset -= 1
r.setEnd(ec, eo-1)
offset = eo
while offset > -1:
try:
r.setEnd(ec, offset)
break
except:
offset -= 1
rects = r.getClientRects() rects = r.getClientRects()
if rects.length > 0: if rects.length > 0:
rect = rects[0] rect = rects[0]