Also add shortcuts to extend selection by para

And rationalize the selection shortcuts
This commit is contained in:
Kovid Goyal 2021-03-15 14:24:24 +05:30
parent 84810e6777
commit 773eb3ee9f
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
4 changed files with 29 additions and 28 deletions

View File

@ -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):

View File

@ -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):

View File

@ -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',

View File

@ -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':