Viewer: Allow modifying the current selection using Ctrl+Shift+arrow. Fixes #1855942 [[Enhancements] Comments and select text with keyboard](https://bugs.launchpad.net/calibre/+bug/1855942)

This commit is contained in:
Kovid Goyal 2019-12-24 21:21:15 +05:30
parent 431d55dbca
commit b13f5d6a0c
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
3 changed files with 21 additions and 1 deletions

View File

@ -106,11 +106,16 @@ class IframeBoss:
'get_current_cfi': self.get_current_cfi,
'set_forward_keypresses': self.set_forward_keypresses,
'set_reference_mode': self.set_reference_mode,
'modify_selection': self.modify_selection,
}
self.comm = IframeClient(handlers)
self.last_window_ypos = 0
self.length_before = None
def modify_selection(self, data):
sel = window.getSelection()
sel.modify('extend', data.direction, data.granularity)
def set_forward_keypresses(self, data):
self.forward_keypresses = data.forward

View File

@ -246,6 +246,18 @@ def shortcuts_definition():
_('Search for next occurrence of selected text'),
),
'extend_selection_by_word': desc(
v"['Ctrl+Shift+ArrowRight']",
'ui',
_('Alter the current selection forward by a word'),
),
'shrink_selection_by_word': desc(
v"['Ctrl+Shift+ArrowLeft']",
'ui',
_('Alter the current selection backwards by a word'),
),
'show_chrome': desc(
v"['Escape', 'ContextMenu']",
'ui',

View File

@ -405,7 +405,10 @@ class View:
self.overlay.show_metadata()
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')
def on_selection_change(self, data):
self.currently_showing.selected_text = data.text