Better fix for ctrl+letter

This commit is contained in:
Kovid Goyal 2019-09-30 09:38:43 +05:30
parent c034aeca4a
commit 0ce7e45327
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -45,11 +45,22 @@ def shortcut_differs(a, b):
return not (a.key is b.key and a.altKey is b.altKey and a.ctrlKey is b.ctrlKey and a.metaKey is b.metaKey and a.shiftKey is b.shiftKey) return not (a.key is b.key and a.altKey is b.altKey and a.ctrlKey is b.ctrlKey and a.metaKey is b.metaKey and a.shiftKey is b.shiftKey)
def get_key_text(evt):
key = evt.key
if key:
cc = key.charCodeAt(0)
# on windows in webengine pressing ctrl+ascii char gives us an ascii
# control code
if 0 < cc < 32 and evt.ctrlKey and not evt.metaKey and not evt.shiftKey and not evt.altKey:
key = chr(96 + cc)
return key
def keyevent_to_index(evt): def keyevent_to_index(evt):
parts = v'[]' parts = v'[]'
for mod in v"['altKey', 'ctrlKey', 'metaKey', 'shiftKey']": for mod in v"['altKey', 'ctrlKey', 'metaKey', 'shiftKey']":
parts.push('y' if evt[mod] else 'n') parts.push('y' if evt[mod] else 'n')
return parts.join('') + evt.key return parts.join('') + get_key_text(evt)
def key_as_text(evt): def key_as_text(evt):
@ -60,7 +71,7 @@ def key_as_text(evt):
mods = '+'.join(mods) mods = '+'.join(mods)
if mods: if mods:
mods += '+' mods += '+'
key = evt.key key = get_key_text(evt)
if key is ' ': if key is ' ':
key = 'Space' key = 'Space'
return mods + key return mods + key
@ -164,15 +175,13 @@ SHORTCUTS = {
), ),
'toggle_toc': desc( 'toggle_toc': desc(
# on windows ctrl+t results in ctrl+\u0014 'Ctrl+t',
v"['Ctrl+t', 'Ctrl+\u0014']",
'ui', 'ui',
_('Show/hide Table of Contents'), _('Show/hide Table of Contents'),
), ),
'start_search': desc( 'start_search': desc(
# on windows ctrl+f results in ctrl+\u0006 v"['/', 'Ctrl+f']",
v"['/', 'Ctrl+f', 'Ctrl+\u0006']",
'ui', 'ui',
_('Start search'), _('Start search'),
), ),