unicode input kitten: Also allow using ctrl+number to switch tabs and pressing any modifier with the function keys

This commit is contained in:
Kovid Goyal 2021-11-17 12:17:46 +05:30
parent 185669ec72
commit 77d7a6180f
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
3 changed files with 15 additions and 8 deletions

View File

@ -23,9 +23,9 @@ the arrow keys/tab to select the character from the displayed matches. You can
also type a space followed by a period and the index for the match if you don't
like to use arrow keys.
You can switch between modes using either the function keys or by pressing
:kbd:`Ctrl+[` and :kbd:`Ctrl+]` or by pressing :kbd:`Ctrl+Tab` and
:kbd:`Ctrl+Shift+Tab`.
You can switch between modes using either the keys :kbd:`F1` ... :kbd:`F4` or
:kbd:`Ctrl+1` ... :kbd:`Ctrl+4` or by pressing :kbd:`Ctrl+[` and :kbd:`Ctrl+]`
or by pressing :kbd:`Ctrl+Tab` and :kbd:`Ctrl+Shift+Tab`.
.. include:: ../generated/cli-kitten-unicode_input.rst

View File

@ -485,19 +485,19 @@ class UnicodeInput(Handler):
if key_event.matches('esc'):
self.quit_loop(1)
return
if key_event.matches('f1'):
if key_event.matches_without_mods('f1') or key_event.matches('ctrl+1'):
self.switch_mode(HEX)
return
if key_event.matches('f2'):
if key_event.matches_without_mods('f2') or key_event.matches('ctrl+2'):
self.switch_mode(NAME)
return
if key_event.matches('f3'):
if key_event.matches_without_mods('f3') or key_event.matches('ctrl+3'):
self.switch_mode(EMOTICONS)
return
if key_event.matches('f4'):
if key_event.matches_without_mods('f4') or key_event.matches('ctrl+4'):
self.switch_mode(FAVORITES)
return
if key_event.matches('f12') and self.mode is FAVORITES:
if key_event.matches_without_mods('f12') and self.mode is FAVORITES:
self.edit_favorites()
return
if key_event.matches('ctrl+shift+tab'):

7
kitty/key_encoding.py generated
View File

@ -227,6 +227,13 @@ class KeyEvent(NamedTuple):
return True
return False
def matches_without_mods(self, spec: Union[str, ParsedShortcut], types: int = EventType.PRESS | EventType.REPEAT) -> bool:
if not self.type & types:
return False
if isinstance(spec, str):
spec = parse_shortcut(spec)
return self.key == spec[1]
def matches_text(self, text: str, case_sensitive: bool = False) -> bool:
if case_sensitive:
return self.text == text