diff options
-rw-r--r-- | src/nvim/keymap.c | 4 | ||||
-rw-r--r-- | src/nvim/tui/input.c | 20 | ||||
-rw-r--r-- | test/functional/ui/input_spec.lua | 4 |
3 files changed, 24 insertions, 4 deletions
diff --git a/src/nvim/keymap.c b/src/nvim/keymap.c index 2b6f022d9d..517274a1d3 100644 --- a/src/nvim/keymap.c +++ b/src/nvim/keymap.c @@ -156,6 +156,7 @@ static const struct key_name_entry { { K_BS, "BS" }, { K_BS, "BackSpace" }, // Alternative name { ESC, "Esc" }, + { ESC, "Escape" }, // Alternative name { CSI, "CSI" }, { K_CSI, "xCSI" }, { '|', "Bar" }, @@ -711,7 +712,8 @@ static int extract_modifiers(int key, int *modp) { int modifiers = *modp; - if (!(modifiers & MOD_MASK_CMD)) { // Command-key is special + // Command-key and ctrl are special + if (!(modifiers & MOD_MASK_CMD) && !(modifiers & MOD_MASK_CTRL)) { if ((modifiers & MOD_MASK_SHIFT) && ASCII_ISALPHA(key)) { key = TOUPPER_ASC(key); modifiers &= ~MOD_MASK_SHIFT; diff --git a/src/nvim/tui/input.c b/src/nvim/tui/input.c index bbee7e4712..94c326a5eb 100644 --- a/src/nvim/tui/input.c +++ b/src/nvim/tui/input.c @@ -9,6 +9,7 @@ #include "nvim/ascii.h" #include "nvim/charset.h" #include "nvim/main.h" +#include "nvim/macros.h" #include "nvim/aucmd.h" #include "nvim/ex_docmd.h" #include "nvim/option.h" @@ -198,13 +199,26 @@ static void forward_modified_utf8(TermInput *input, TermKeyKey *key) char buf[64]; if (key->type == TERMKEY_TYPE_KEYSYM - && key->code.sym == TERMKEY_SYM_ESCAPE) { - len = (size_t)snprintf(buf, sizeof(buf), "<Esc>"); - } else if (key->type == TERMKEY_TYPE_KEYSYM && key->code.sym == TERMKEY_SYM_SUSPEND) { len = (size_t)snprintf(buf, sizeof(buf), "<C-Z>"); + } else if (key->type != TERMKEY_TYPE_UNICODE) { + len = termkey_strfkey(input->tk, buf, sizeof(buf), key, TERMKEY_FORMAT_VIM); } else { + assert(key->modifiers); + // Termkey doesn't include the S- modifier for ASCII characters (e.g., + // ctrl-shift-l is <C-L> instead of <C-S-L>. Vim, on the other hand, + // treats <C-L> and <C-l> the same, requiring the S- modifier. len = termkey_strfkey(input->tk, buf, sizeof(buf), key, TERMKEY_FORMAT_VIM); + if ((key->modifiers & TERMKEY_KEYMOD_CTRL) + && !(key->modifiers & TERMKEY_KEYMOD_SHIFT) + && ASCII_ISUPPER(key->code.codepoint)) { + assert(len <= 62); + // Make remove for the S- + memmove(buf + 3, buf + 1, len - 1); + buf[1] = 'S'; + buf[2] = '-'; + len += 2; + } } tinput_enqueue(input, buf, len); diff --git a/test/functional/ui/input_spec.lua b/test/functional/ui/input_spec.lua index 12d0e4f40b..9313a35708 100644 --- a/test/functional/ui/input_spec.lua +++ b/test/functional/ui/input_spec.lua @@ -23,6 +23,8 @@ describe('mappings', function() before_each(function() clear() cid = nvim('get_api_info')[1] + add_mapping('<C-L>', '<C-L>') + add_mapping('<C-S-L>', '<C-S-L>') add_mapping('<s-up>', '<s-up>') add_mapping('<s-up>', '<s-up>') add_mapping('<c-s-up>', '<c-s-up>') @@ -51,6 +53,8 @@ describe('mappings', function() end) it('ok', function() + check_mapping('<C-L>', '<C-L>') + check_mapping('<C-S-L>', '<C-S-L>') check_mapping('<s-up>', '<s-up>') check_mapping('<c-s-up>', '<c-s-up>') check_mapping('<s-c-up>', '<c-s-up>') |