From 60ba6e370519ede5aa248b158595e0395c250e39 Mon Sep 17 00:00:00 2001 From: Jendrik Seipp Date: Sat, 17 Feb 2024 22:39:47 +0100 Subject: [PATCH] Allow copying text in preview mode (fixes #732). --- CHANGELOG.md | 1 + rednotebook/gui/browser.py | 3 +++ rednotebook/gui/menu.py | 19 +++++++++++-------- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b9b3299b..12ce6800 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,5 @@ # next (unreleased) +* Allow copying text in preview mode (#732, Jendrik Seipp). * Allow hashtags that start with (but are longer than) hex color codes and preprocessor directives (#738, Jendrik Seipp). * Highlight hashtags and formatting within lists (#744, Jendrik Seipp). * Test macOS 12 and 13 instead of 11 and 12 (Jendrik Seipp). diff --git a/rednotebook/gui/browser.py b/rednotebook/gui/browser.py index 795d630d..9c5b78d3 100644 --- a/rednotebook/gui/browser.py +++ b/rednotebook/gui/browser.py @@ -67,3 +67,6 @@ def on_load_changed(self, webview, event): self.highlight(self.search_text) else: webview.get_find_controller().search_finish() + + def copy_to_clipboard(self): + self.execute_editing_command(WebKit2.EDITING_COMMAND_COPY) diff --git a/rednotebook/gui/menu.py b/rednotebook/gui/menu.py index 55c73ac7..66aa8ab0 100644 --- a/rednotebook/gui/menu.py +++ b/rednotebook/gui/menu.py @@ -363,20 +363,23 @@ def on_redo(self, widget): editor = self.main_window.day_text_field editor.day_text_buffer.redo() - def _get_active_editor_widget(self): + def on_copy_menu_item_activate(self, widget): if self.main_window.preview_mode: - return self.main_window.html_editor + self.main_window.html_editor.copy_to_clipboard() else: - return self.main_window.day_text_field.day_text_view - - def on_copy_menu_item_activate(self, widget): - self._get_active_editor_widget().emit("copy_clipboard") + self.main_window.day_text_field.day_text_view.emit("copy_clipboard") def on_paste_menu_item_activate(self, widget): - self._get_active_editor_widget().emit("paste_clipboard") + if self.main_window.preview_mode: + pass + else: + self.main_window.day_text_field.day_text_view.emit("paste_clipboard") def on_cut_menu_item_activate(self, widget): - self._get_active_editor_widget().emit("cut_clipboard") + if self.main_window.preview_mode: + pass + else: + self.main_window.day_text_field.day_text_view.emit("cut_clipboard") def on_fullscreen_menuitem_activate(self, widget): self.main_window.toggle_fullscreen()