E-book viewer: Fix searching does not jump to first match if all matches are before current position in book. Fixes #2034977 [Ebook-viewer: viewer doesn't jump to search match position in *.fb2 books under some conditions](https://bugs.launchpad.net/calibre/+bug/2034977)

This commit is contained in:
Kovid Goyal 2023-09-20 16:07:20 +05:30
parent 2aa94956ac
commit ded1932795
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
3 changed files with 18 additions and 2 deletions

View File

@ -817,6 +817,7 @@ class SearchPanel(QWidget): # {{{
self.results.ensure_current_result_visible()
else:
self.show_no_results_found()
self.show_search_result.emit({'on_discovery': True, 'search_finished': True, 'result_num': -1})
return
self.results.add_result(result)
obj = result.for_js

View File

@ -781,7 +781,7 @@ class IframeBoss:
self.load_search_result_timer = window.setTimeout(self.ensure_search_result_visible.bind(None, before_select_pos), int(3 * ONSCROLL_DEBOUNCE_TIME / 4))
if self.full_book_search_in_progress and not self.full_book_search_in_progress.first_result_shown and sr.on_discovery:
discovered = False
if progress_frac() >= self.full_book_search_in_progress.progress_frac_at_start or current_spine_item().index is not self.full_book_search_in_progress.start_spine_index:
if sr.force_jump_to or progress_frac() >= self.full_book_search_in_progress.progress_frac_at_start or current_spine_item().index is not self.full_book_search_in_progress.start_spine_index:
self.full_book_search_in_progress.first_result_shown = True
discovered = True
else:

View File

@ -1409,8 +1409,19 @@ class View:
ui_operations.reference_mode_changed(self.reference_mode_enabled)
def discover_search_result(self, sr):
if sr.search_finished:
if self.search_result_discovery:
self.search_result_discovery.finished = True
if not self.search_result_discovery.discovered and self.search_result_discovery.first_search_result and self.search_result_discovery.queue.length is 0:
sr = self.search_result_discovery.first_search_result
sr.force_jump_to = True
self.show_search_result(sr)
return
if sr.result_num is 1:
self.search_result_discovery = {'queue': v'[]', 'on_discovery': sr.on_discovery, 'in_flight': None, 'discovered': False}
self.search_result_discovery = {
'queue': v'[]', 'on_discovery': sr.on_discovery, 'in_flight': None, 'discovered': False,
'first_search_result': sr, 'finished': False,
}
if not self.search_result_discovery or self.search_result_discovery.discovered or self.search_result_discovery.on_discovery is not sr.on_discovery:
return
self.search_result_discovery.queue.push(sr)
@ -1426,6 +1437,10 @@ class View:
ui_operations.search_result_discovered(sr)
elif not self.search_result_discovery.discovered and self.search_result_discovery.queue.length:
self.show_search_result(self.search_result_discovery.queue.shift())
elif not self.search_result_discovery.discovered and self.search_result_discovery.finished:
sr = self.search_result_discovery.first_search_result
sr.force_jump_to = True
self.show_search_result(sr)
def search_result_discovered(self, data):
self.handle_search_result_discovery(data.search_result, data.discovered)