Skip to content

Commit

Permalink
Allow copying text in preview mode (fixes #732).
Browse files Browse the repository at this point in the history
  • Loading branch information
jendrikseipp committed Feb 17, 2024
1 parent 5f05078 commit 60ba6e3
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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).
Expand Down
3 changes: 3 additions & 0 deletions rednotebook/gui/browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
19 changes: 11 additions & 8 deletions rednotebook/gui/menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 60ba6e3

Please sign in to comment.