diff --git a/src/calibre/gui2/viewer/highlights.py b/src/calibre/gui2/viewer/highlights.py index f577cc1161..b795f7f5d7 100644 --- a/src/calibre/gui2/viewer/highlights.py +++ b/src/calibre/gui2/viewer/highlights.py @@ -161,6 +161,15 @@ class Highlights(QListWidget): return True return False + def find_annot_id(self, annot_id): + for i in range(self.count()): + item = self.item(i) + h = item.data(Qt.UserRole) + if h.get('uuid') == annot_id: + self.set_current_row(i) + return True + return False + def set_current_row(self, row): self.setCurrentRow(row, QItemSelectionModel.ClearAndSelect) @@ -363,3 +372,7 @@ class HighlightsPanel(QWidget): if not hl: return error_dialog(self, _('No highlights'), _('This book has no highlights to export'), show=True) Export(hl, self).exec_() + + def selected_text_changed(self, text, annot_id): + if annot_id: + self.highlights.find_annot_id(annot_id) diff --git a/src/calibre/gui2/viewer/lookup.py b/src/calibre/gui2/viewer/lookup.py index 0cf65dfb6d..9c896b5414 100644 --- a/src/calibre/gui2/viewer/lookup.py +++ b/src/calibre/gui2/viewer/lookup.py @@ -337,6 +337,6 @@ class Lookup(QWidget): self.view.load(QUrl(url)) self.current_query = query - def selected_text_changed(self, text): + def selected_text_changed(self, text, annot_id): self.selected_text = text or '' self.debounce_timer.start() diff --git a/src/calibre/gui2/viewer/ui.py b/src/calibre/gui2/viewer/ui.py index fa19ab05c7..802dd9b7c8 100644 --- a/src/calibre/gui2/viewer/ui.py +++ b/src/calibre/gui2/viewer/ui.py @@ -175,6 +175,7 @@ class EbookViewer(MainWindow): self.web_view.toggle_full_screen.connect(self.toggle_full_screen) self.web_view.ask_for_open.connect(self.ask_for_open, type=Qt.QueuedConnection) self.web_view.selection_changed.connect(self.lookup_widget.selected_text_changed, type=Qt.QueuedConnection) + self.web_view.selection_changed.connect(self.highlights_widget.selected_text_changed, type=Qt.QueuedConnection) self.web_view.view_image.connect(self.view_image, type=Qt.QueuedConnection) self.web_view.copy_image.connect(self.copy_image, type=Qt.QueuedConnection) self.web_view.show_loading_message.connect(self.show_loading_message) diff --git a/src/calibre/gui2/viewer/web_view.py b/src/calibre/gui2/viewer/web_view.py index 36d82bbab0..76cb7d8fb3 100644 --- a/src/calibre/gui2/viewer/web_view.py +++ b/src/calibre/gui2/viewer/web_view.py @@ -249,7 +249,7 @@ class ViewerBridge(Bridge): toggle_full_screen = from_js() report_cfi = from_js(object, object) ask_for_open = from_js(object) - selection_changed = from_js(object) + selection_changed = from_js(object, object) autoscroll_state_changed = from_js(object) copy_selection = from_js(object) view_image = from_js(object) @@ -443,7 +443,7 @@ class WebView(RestartingWebEngineView): update_current_toc_nodes = pyqtSignal(object, object) toggle_full_screen = pyqtSignal() ask_for_open = pyqtSignal(object) - selection_changed = pyqtSignal(object) + selection_changed = pyqtSignal(object, object) autoscroll_state_changed = pyqtSignal(object) view_image = pyqtSignal(object) copy_image = pyqtSignal(object) diff --git a/src/pyj/read_book/view.pyj b/src/pyj/read_book/view.pyj index 3f07b6b5db..0b4547fd07 100644 --- a/src/pyj/read_book/view.pyj +++ b/src/pyj/read_book/view.pyj @@ -541,7 +541,7 @@ class View: 'selection_change_caused_by_search': data.selection_change_caused_by_search } if ui_operations.selection_changed: - ui_operations.selection_changed(self.currently_showing.selection.text) + ui_operations.selection_changed(self.currently_showing.selection.text, self.currently_showing.selection.annot_id) self.selection_bar.update_position() def update_selection_position(self, data): diff --git a/src/pyj/viewer-main.pyj b/src/pyj/viewer-main.pyj index f021905480..e718fb06a9 100644 --- a/src/pyj/viewer-main.pyj +++ b/src/pyj/viewer-main.pyj @@ -351,8 +351,8 @@ if window is window.top: to_python.quit() ui_operations.toggle_lookup = def(force_show): to_python.toggle_lookup(v'!!force_show') - ui_operations.selection_changed = def(selected_text): - to_python.selection_changed(selected_text) + ui_operations.selection_changed = def(selected_text, annot_id): + to_python.selection_changed(selected_text, annot_id or None) ui_operations.update_current_toc_nodes = def(current_node_id, top_level_node_id): to_python.update_current_toc_nodes(current_node_id, top_level_node_id) ui_operations.toggle_full_screen = def():