From d5096c09b6cc7f2a49f191b4707f84727598122b Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 4 Dec 2013 17:52:38 +0530 Subject: [PATCH] Fix off by one error when finding closest line number for an element --- src/calibre/gui2/tweak_book/preview.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/calibre/gui2/tweak_book/preview.py b/src/calibre/gui2/tweak_book/preview.py index a2b8ecf00e..e112312bcb 100644 --- a/src/calibre/gui2/tweak_book/preview.py +++ b/src/calibre/gui2/tweak_book/preview.py @@ -266,10 +266,10 @@ def uniq(vals): def find_le(a, x): 'Find rightmost value in a less than or equal to x' - i = bisect_right(a, x) - if i: - return a[i-1] - raise ValueError + try: + return a[bisect_right(a, x)] + except IndexError: + return a[-1] class WebPage(QWebPage):