From 77d7a6180f87550238eec0d91b26d625959092e9 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 17 Nov 2021 12:17:46 +0530 Subject: [PATCH] unicode input kitten: Also allow using ctrl+number to switch tabs and pressing any modifier with the function keys --- docs/kittens/unicode-input.rst | 6 +++--- kittens/unicode_input/main.py | 10 +++++----- kitty/key_encoding.py | 7 +++++++ 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/docs/kittens/unicode-input.rst b/docs/kittens/unicode-input.rst index 52e7d7772..1e2a53766 100644 --- a/docs/kittens/unicode-input.rst +++ b/docs/kittens/unicode-input.rst @@ -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 diff --git a/kittens/unicode_input/main.py b/kittens/unicode_input/main.py index f7132858a..b07a09571 100644 --- a/kittens/unicode_input/main.py +++ b/kittens/unicode_input/main.py @@ -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'): diff --git a/kitty/key_encoding.py b/kitty/key_encoding.py index 61f0dfbce..95f2ef545 100644 --- a/kitty/key_encoding.py +++ b/kitty/key_encoding.py @@ -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