unicode input kitten: Allow pressing :kbd:ctrl+tab to change the input mode

Fixes #2343
This commit is contained in:
Kovid Goyal 2020-02-08 13:29:50 +05:30
parent d82f399be7
commit 62e273c5bb
No known key found for this signature in database
GPG key ID: 06BC317B515ACE7C
3 changed files with 38 additions and 20 deletions

View file

@ -22,6 +22,9 @@ To update |kitty|, :doc:`follow the instructions <binary>`.
- 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]
--------------------

View file

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

View file

@ -15,7 +15,7 @@
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 @@
'îïðñòóôõöøœš' 'ùúûüýÿþªºαΩ∞'
))
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 @@ def initialize(self):
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 @@ def on_key(self, key_event):
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 @@ def switch_mode(self, mode):
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)