mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-08 10:44:09 -04:00
E-book viewer: Fix broken backwards searching
This commit is contained in:
parent
3be66119d0
commit
a172785529
@ -96,7 +96,10 @@ class EbookIterator(object):
|
||||
|
||||
def search(self, text, index, backwards=False):
|
||||
text = text.lower()
|
||||
for i, path in enumerate(self.spine):
|
||||
pmap = [(i, path) for i, path in enumerate(self.spine)]
|
||||
if backwards:
|
||||
pmap.reverse()
|
||||
for i, path in pmap:
|
||||
if (backwards and i < index) or (not backwards and i > index):
|
||||
if text in open(path, 'rb').read().decode(path.encoding).lower():
|
||||
return i
|
||||
|
@ -614,7 +614,7 @@ class DocumentView(QWebView):
|
||||
|
||||
def search(self, text, backwards=False):
|
||||
if backwards:
|
||||
return self.findText(text, self.document.FindBackwards)
|
||||
return self.findText(text, self.document.FindBackward)
|
||||
return self.findText(text)
|
||||
|
||||
def path(self):
|
||||
|
@ -172,6 +172,7 @@ class EbookViewer(MainWindow, Ui_EbookViewer):
|
||||
self.iterator = None
|
||||
self.current_page = None
|
||||
self.pending_search = None
|
||||
self.pending_search_dir= None
|
||||
self.pending_anchor = None
|
||||
self.pending_reference = None
|
||||
self.pending_bookmark = None
|
||||
@ -435,7 +436,7 @@ class EbookViewer(MainWindow, Ui_EbookViewer):
|
||||
if not text:
|
||||
self.view.search('')
|
||||
return self.search.search_done(False)
|
||||
if self.view.search(text):
|
||||
if self.view.search(text, backwards=backwards):
|
||||
self.scrolled(self.view.scroll_fraction)
|
||||
return self.search.search_done(True)
|
||||
index = self.iterator.search(text, self.current_index,
|
||||
@ -449,11 +450,13 @@ class EbookViewer(MainWindow, Ui_EbookViewer):
|
||||
return self.search.search_done(True)
|
||||
return self.search.search_done(True)
|
||||
self.pending_search = text
|
||||
self.pending_search_dir = 'backwards' if backwards else 'forwards'
|
||||
self.load_path(self.iterator.spine[index])
|
||||
|
||||
def do_search(self, text):
|
||||
def do_search(self, text, backwards):
|
||||
self.pending_search = None
|
||||
if self.view.search(text):
|
||||
self.pending_search_dir = None
|
||||
if self.view.search(text, backwards=backwards):
|
||||
self.scrolled(self.view.scroll_fraction)
|
||||
|
||||
def keyPressEvent(self, event):
|
||||
@ -499,8 +502,10 @@ class EbookViewer(MainWindow, Ui_EbookViewer):
|
||||
self.current_index = index
|
||||
self.set_page_number(self.view.scroll_fraction)
|
||||
if self.pending_search is not None:
|
||||
self.do_search(self.pending_search)
|
||||
self.do_search(self.pending_search,
|
||||
self.pending_search_dir=='backwards')
|
||||
self.pending_search = None
|
||||
self.pending_search_dir = None
|
||||
if self.pending_anchor is not None:
|
||||
self.view.scroll_to(self.pending_anchor)
|
||||
self.pending_anchor = None
|
||||
|
Loading…
x
Reference in New Issue
Block a user