From 773eb3ee9fc7aa058819478755437e0875ed843e Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 15 Mar 2021 14:24:24 +0530 Subject: [PATCH] Also add shortcuts to extend selection by para And rationalize the selection shortcuts --- src/pyj/read_book/iframe.pyj | 6 +++++- src/pyj/read_book/selection_bar.pyj | 10 +--------- src/pyj/read_book/shortcuts.pyj | 25 +++++++++++++++++++------ src/pyj/read_book/view.pyj | 16 ++++------------ 4 files changed, 29 insertions(+), 28 deletions(-) diff --git a/src/pyj/read_book/iframe.pyj b/src/pyj/read_book/iframe.pyj index 62d8918a52..792c4854f1 100644 --- a/src/pyj/read_book/iframe.pyj +++ b/src/pyj/read_book/iframe.pyj @@ -185,7 +185,11 @@ class IframeBoss: def modify_selection(self, data): sel = window.getSelection() - sel.modify('extend', data.direction, data.granularity) + try: + sel.modify('extend', data.direction, data.granularity) + except: + if data.granularity is 'paragraph': + sel.modify('extend', data.direction, 'line') self.ensure_selection_visible() def initialize(self, data): diff --git a/src/pyj/read_book/selection_bar.pyj b/src/pyj/read_book/selection_bar.pyj index 94a7dca769..bc39ebed54 100644 --- a/src/pyj/read_book/selection_bar.pyj +++ b/src/pyj/read_book/selection_bar.pyj @@ -576,19 +576,11 @@ class SelectionBar: self.copy_to_clipboard() return sc_name = shortcut_for_key_event(ev, self.view.keyboard_shortcut_map) - if ev.key is 'ArrowRight' and ev.shiftKey and not ev.altKey: - sc_name = 'extend_selection_by_word' - elif ev.key is 'ArrowLeft' and ev.shiftKey and not ev.altKey: - sc_name = 'shrink_selection_by_word' - if not sc_name: return forwarded = { 'toggle_highlights': True, 'edit_book': True, - 'extend_selection_by_word': True, 'shrink_selection_by_word': True, - 'extend_selection_by_character': True, 'shrink_selection_by_character': True, - 'extend_selection_by_line': True, 'shrink_selection_by_line': True, } if sc_name is 'show_chrome': self.clear_selection() @@ -600,7 +592,7 @@ class SelectionBar: self.book_search() elif sc_name is 'new_bookmark': self.new_bookmark() - elif forwarded[sc_name]: + elif sc_name.startsWith('shrink_selection_by_') or sc_name.startsWith('extend_selection_by_') or forwarded[sc_name]: self.view.on_handle_shortcut({'name': sc_name}) def report_failed_edit_highlight(self, annot_id): diff --git a/src/pyj/read_book/shortcuts.pyj b/src/pyj/read_book/shortcuts.pyj index 6c8676265d..f7582e3b31 100644 --- a/src/pyj/read_book/shortcuts.pyj +++ b/src/pyj/read_book/shortcuts.pyj @@ -171,13 +171,13 @@ def common_shortcuts(): # {{{ ), 'back': desc( - v"['Alt+ArrowLeft', 'Shift+ArrowLeft']", + v"['Alt+ArrowLeft']", 'scroll', _('Back'), ), 'forward': desc( - v"['Alt+ArrowRight', 'Shift+ArrowRight']", + v"['Alt+ArrowRight']", 'scroll', _('Forward'), ), @@ -327,29 +327,42 @@ def common_shortcuts(): # {{{ ), 'extend_selection_by_character': desc( - v"['Alt+Shift+ArrowRight']", + v"['Shift+ArrowRight']", 'ui', _('Alter the current selection forward by a character'), ), 'shrink_selection_by_character': desc( - v"['Alt+Shift+ArrowLeft']", + v"['Shift+ArrowLeft']", 'ui', _('Alter the current selection backwards by a character'), ), 'extend_selection_by_line': desc( - v"['Ctrl+Shift+ArrowDown', 'Shift+ArrowDown']", + v"['Shift+ArrowDown']", 'ui', _('Alter the current selection forward by a line'), ), 'shrink_selection_by_line': desc( - v"['Ctrl+Shift+ArrowUp', 'Shift+ArrowUp']", + v"['Shift+ArrowUp']", 'ui', _('Alter the current selection backwards by a line'), ), + 'extend_selection_by_paragraph': desc( + v"['Ctrl+Shift+ArrowDown']", + 'ui', + _('Alter the current selection forward by a paragraph'), + ), + + 'shrink_selection_by_paragraph': desc( + v"['Ctrl+Shift+ArrowUp']", + 'ui', + _('Alter the current selection backwards by a paragraph'), + ), + + 'show_chrome': desc( v"['Escape', 'ContextMenu']", 'ui', diff --git a/src/pyj/read_book/view.pyj b/src/pyj/read_book/view.pyj index 8ba6cff266..16b992aaf3 100644 --- a/src/pyj/read_book/view.pyj +++ b/src/pyj/read_book/view.pyj @@ -559,18 +559,10 @@ class View: ui_operations.edit_book(current_spine_item(), self.current_file_progress_frac, self.currently_showing?.selection?.text) elif data.name is 'goto_location': self.overlay.show_ask_for_location() - elif data.name is 'shrink_selection_by_word': - self.iframe_wrapper.send_message('modify_selection', direction='backward', granularity='word') - elif data.name is 'extend_selection_by_word': - self.iframe_wrapper.send_message('modify_selection', direction='forward', granularity='word') - elif data.name is 'shrink_selection_by_character': - self.iframe_wrapper.send_message('modify_selection', direction='backward', granularity='character') - elif data.name is 'extend_selection_by_character': - self.iframe_wrapper.send_message('modify_selection', direction='forward', granularity='character') - elif data.name is 'shrink_selection_by_line': - self.iframe_wrapper.send_message('modify_selection', direction='backward', granularity='line') - elif data.name is 'extend_selection_by_line': - self.iframe_wrapper.send_message('modify_selection', direction='forward', granularity='line') + elif data.name.startsWith('shrink_selection_by_'): + self.iframe_wrapper.send_message('modify_selection', direction='backward', granularity=data.name.rpartition('_')[-1]) + elif data.name.startsWith('extend_selection_by_'): + self.iframe_wrapper.send_message('modify_selection', direction='forward', granularity=data.name.rpartition('_')[-1]) elif data.name is 'scrollspeed_increase': self.update_scroll_speed(SCROLL_SPEED_STEP) elif data.name is 'scrollspeed_decrease':