Fix #1878123 [[Enhancement - Viewer] Opening the search panel with text selected should add the selected text in the search field](https://bugs.launchpad.net/calibre/+bug/1878123)

This commit is contained in:
Kovid Goyal 2020-05-12 09:12:48 +05:30
parent 1a1c4359dc
commit 23442569d7
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 9 additions and 4 deletions

View File

@ -333,7 +333,9 @@ class SearchInput(QWidget): # {{{
def find_previous(self):
self.emit_search(backwards=True)
def focus_input(self):
def focus_input(self, text=None):
if text and hasattr(text, 'rstrip'):
self.search_box.setText(text)
self.search_box.setFocus(Qt.OtherFocusReason)
le = self.search_box.lineEdit()
le.end(False)
@ -454,8 +456,8 @@ class SearchPanel(QWidget): # {{{
def update_hidden_message(self):
self.hidden_message.setVisible(self.results.current_result_is_hidden)
def focus_input(self):
self.search_input.focus_input()
def focus_input(self, text=None):
self.search_input.focus_input(text)
def start_search(self, search_query, current_name):
if self.current_search is not None and search_query == self.current_search:

View File

@ -288,10 +288,13 @@ class EbookViewer(MainWindow):
self.toc_dock.setVisible(not self.toc_dock.isVisible())
def show_search(self):
self.web_view.get_current_cfi(self.show_search_with_current_selection)
def show_search_with_current_selection(self, pos_data):
self.search_dock.setVisible(True)
self.search_dock.activateWindow()
self.search_dock.raise_()
self.search_widget.focus_input()
self.search_widget.focus_input(pos_data.get('selected_text'))
def start_search(self, search_query):
name = self.web_view.current_content_file