diff --git a/docs/keyboard-protocol.rst b/docs/keyboard-protocol.rst index ee30aa9ce..539f53693 100644 --- a/docs/keyboard-protocol.rst +++ b/docs/keyboard-protocol.rst @@ -240,7 +240,11 @@ represented in one of the following two forms:: This makes it very easy to parse key events in an application. In particular, :kbd:`ctrl+c` will no longer generate the ``SIGINT`` signal, but instead be delivers as a ``CSI u`` escape code. This has the nice side effect of making it -much easier to integrate into the application event loop. +much easier to integrate into the application event loop. The only exceptions +are the :kbd:`Enter, Tab and Backspace` keys which still generate the same +bytes as in legacy mode this is to allow the user to type and execute commands +in the shell such as ``reset`` after a program that sets this mode crashes +without clearing it. .. _report_events: diff --git a/kitty/key_encoding.c b/kitty/key_encoding.c index eace1d24f..ddfb92874 100644 --- a/kitty/key_encoding.c +++ b/kitty/key_encoding.c @@ -150,15 +150,15 @@ encode_function_key(const KeyEvent *ev, char *output) { default: break; } } - if (ev->mods.value == ALT) { + if (ev->mods.value == ALT && !ev->disambiguate) { switch(key_number) { case GLFW_FKEY_TAB: SIMPLE("\x1b\t"); case GLFW_FKEY_ENTER: SIMPLE("\x1b\r"); case GLFW_FKEY_BACKSPACE: SIMPLE("\x1b\x7f"); } } - if (ev->mods.value == SHIFT && key_number == GLFW_FKEY_TAB) { SIMPLE("\x1b[Z"); } - if (ev->mods.value == CTRL && key_number == GLFW_FKEY_BACKSPACE) { SIMPLE("\x08"); } + if (ev->mods.value == SHIFT && key_number == GLFW_FKEY_TAB && !ev->disambiguate) { SIMPLE("\x1b[Z"); } + if (ev->mods.value == CTRL && key_number == GLFW_FKEY_BACKSPACE && !ev->disambiguate) { SIMPLE("\x08"); } #undef SIMPLE #define S(number, trailer) key_number = number; csi_trailer = trailer; break diff --git a/kitty_tests/keys.py b/kitty_tests/keys.py index f49fa329a..b50449d14 100644 --- a/kitty_tests/keys.py +++ b/kitty_tests/keys.py @@ -399,7 +399,11 @@ class TestKeys(BaseTest): # test disambiguate dq = partial(enc, key_encoding_flags=0b1) ae(dq(ord('a')), 'a') - ae(dq(defines.GLFW_FKEY_ESCAPE), csi(num=27)) # esc + ae(dq(defines.GLFW_FKEY_ESCAPE), csi(num=27)) + ae(dq(defines.GLFW_FKEY_ENTER), '\r') + ae(dq(defines.GLFW_FKEY_ENTER, mods=shift), csi(shift, 13)) + ae(dq(defines.GLFW_FKEY_TAB), '\t') + ae(dq(defines.GLFW_FKEY_BACKSPACE), '\x7f') for mods in (ctrl, alt, ctrl | shift, alt | shift): ae(dq(ord('a'), mods=mods), csi(mods, ord('a'))) ae(dq(ord(' '), mods=ctrl), csi(ctrl, ord(' ')))