From 62e273c5bbb4e671f3e40c3711bfedb625ee54c5 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sat, 8 Feb 2020 13:29:50 +0530 Subject: [PATCH] unicode input kitten: Allow pressing :kbd:`ctrl+tab` to change the input mode Fixes #2343 --- docs/changelog.rst | 3 ++ docs/kittens/unicode-input.rst | 4 +++ kittens/unicode_input/main.py | 51 +++++++++++++++++++++------------- 3 files changed, 38 insertions(+), 20 deletions(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index 5b4dbca05..1d9212c4e 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -22,6 +22,9 @@ To update |kitty|, :doc:`follow the instructions `. - X11: Fix arrow mouse cursor using right pointing instead of the default left pointing arrow (:iss:`2341`) +- unicode input kitten: Allow pressing :kbd:`ctrl+tab` to change the input mode + (:iss:`2343`) + 0.16.0 [2020-01-28] -------------------- diff --git a/docs/kittens/unicode-input.rst b/docs/kittens/unicode-input.rst index e3f463802..ff060f5f2 100644 --- a/docs/kittens/unicode-input.rst +++ b/docs/kittens/unicode-input.rst @@ -23,6 +23,10 @@ keys/tab to select the character from the displayed matches. You can also type a leading 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+Tab`. + + Command Line Interface ------------------------- diff --git a/kittens/unicode_input/main.py b/kittens/unicode_input/main.py index 2fcbd6b76..0470cfe05 100644 --- a/kittens/unicode_input/main.py +++ b/kittens/unicode_input/main.py @@ -15,7 +15,7 @@ from kitty.config import cached_values_for from kitty.constants import config_dir from kitty.fast_data_types import wcswidth, is_emoji_presentation_base from kitty.key_encoding import ( - DOWN, ESCAPE, F1, F2, F3, F4, F12, LEFT, RELEASE, RIGHT, SHIFT, TAB, UP, + DOWN, ESCAPE, F1, F2, F3, F4, F12, LEFT, RELEASE, RIGHT, SHIFT, TAB, UP, CTRL, enter_key ) from kitty.utils import get_editor @@ -38,6 +38,12 @@ DEFAULT_SET = tuple(map( 'îïðñòóôõöøœš' 'ùúûüýÿþªºαΩ∞' )) EMOTICONS_SET = tuple(range(0x1f600, 0x1f64f + 1)) +all_modes = ( + (_('Code'), 'F1', HEX), + (_('Name'), 'F2', NAME), + (_('Emoji'), 'F3', EMOTICONS), + (_('Favorites'), 'F4', FAVORITES), +) def codepoint_ok(code): @@ -355,12 +361,7 @@ class UnicodeInput(Handler): def draw_title_bar(self): entries = [] - for name, key, mode in [ - (_('Code'), 'F1', HEX), - (_('Name'), 'F2', NAME), - (_('Emoji'), 'F3', EMOTICONS), - (_('Favorites'), 'F4', FAVORITES), - ]: + for name, key, mode in all_modes: entry = ' {} ({}) '.format(name, key) if mode is self.mode: entry = styled(entry, reverse=False, bold=True) @@ -452,19 +453,24 @@ class UnicodeInput(Handler): return if key_event is enter_key: self.quit_loop(0) - elif key_event.type is RELEASE and not key_event.mods: - if key_event.key is ESCAPE: - self.quit_loop(1) - elif key_event.key is F1: - self.switch_mode(HEX) - elif key_event.key is F2: - self.switch_mode(NAME) - elif key_event.key is F3: - self.switch_mode(EMOTICONS) - elif key_event.key is F4: - self.switch_mode(FAVORITES) - elif key_event.key is F12 and self.mode is FAVORITES: - self.edit_favorites() + elif key_event.type is RELEASE: + if not key_event.mods: + if key_event.key is ESCAPE: + self.quit_loop(1) + elif key_event.key is F1: + self.switch_mode(HEX) + elif key_event.key is F2: + self.switch_mode(NAME) + elif key_event.key is F3: + self.switch_mode(EMOTICONS) + elif key_event.key is F4: + self.switch_mode(FAVORITES) + elif key_event.key is F12 and self.mode is FAVORITES: + self.edit_favorites() + elif key_event.mods == CTRL and key_event.key is TAB: + self.next_mode() + elif key_event.mods == CTRL | SHIFT and key_event.key is TAB: + self.next_mode(-1) def edit_favorites(self): if not os.path.exists(favorites_path): @@ -486,6 +492,11 @@ class UnicodeInput(Handler): self.choice_line = '' self.refresh() + def next_mode(self, delta=1): + modes = tuple(x[-1] for x in all_modes) + idx = (modes.index(self.mode) + delta + len(modes)) % len(modes) + self.switch_mode(modes[idx]) + def on_interrupt(self): self.quit_loop(1)