diff options
author | zeertzjq <zeertzjq@outlook.com> | 2022-04-29 20:50:14 +0800 |
---|---|---|
committer | zeertzjq <zeertzjq@outlook.com> | 2022-04-29 21:12:48 +0800 |
commit | 98f62a2cfa98363217fdfcf96b6c636e91dba84d (patch) | |
tree | e3b037813de3eb2f0133608d2a5d3df6bd9ef123 | |
parent | 8c548c9e5416b4e25b51c018ceaa433756ee99b1 (diff) | |
download | rneovim-98f62a2cfa98363217fdfcf96b6c636e91dba84d.tar.gz rneovim-98f62a2cfa98363217fdfcf96b6c636e91dba84d.tar.bz2 rneovim-98f62a2cfa98363217fdfcf96b6c636e91dba84d.zip |
feat(mappings): allow special keys and modifiers in <Cmd> mapping
-rw-r--r-- | src/nvim/getchar.c | 20 | ||||
-rw-r--r-- | src/nvim/globals.h | 4 | ||||
-rw-r--r-- | test/functional/ex_cmds/cmd_map_spec.lua | 29 |
3 files changed, 37 insertions, 16 deletions
diff --git a/src/nvim/getchar.c b/src/nvim/getchar.c index eb78317ee7..0ce8f6e715 100644 --- a/src/nvim/getchar.c +++ b/src/nvim/getchar.c @@ -4861,15 +4861,21 @@ char_u *getcmdkeycmd(int promptc, void *cookie, int indent, bool do_concat) // special case to give nicer error message emsg(e_cmdmap_repeated); aborted = true; - } else if (IS_SPECIAL(c1)) { - if (c1 == K_SNR) { - ga_concat(&line_ga, "<SNR>"); + } else if (c1 == K_SNR) { + ga_concat(&line_ga, "<SNR>"); + } else { + if (cmod != 0) { + ga_append(&line_ga, (char)K_SPECIAL); + ga_append(&line_ga, (char)KS_MODIFIER); + ga_append(&line_ga, (char)cmod); + } + if (IS_SPECIAL(c1)) { + ga_append(&line_ga, (char)K_SPECIAL); + ga_append(&line_ga, (char)K_SECOND(c1)); + ga_append(&line_ga, (char)K_THIRD(c1)); } else { - semsg(e_cmdmap_key, get_special_key_name(c1, cmod)); - aborted = true; + ga_append(&line_ga, (char)c1); } - } else { - ga_append(&line_ga, (char)c1); } cmod = 0; diff --git a/src/nvim/globals.h b/src/nvim/globals.h index 5983f18bb5..070d96ebb3 100644 --- a/src/nvim/globals.h +++ b/src/nvim/globals.h @@ -997,8 +997,8 @@ EXTERN char e_float_as_string[] INIT(= N_("E806: using Float as a String")); EXTERN char e_autocmd_err[] INIT(= N_("E5500: autocmd has thrown an exception: %s")); EXTERN char e_cmdmap_err[] INIT(= N_("E5520: <Cmd> mapping must end with <CR>")); -EXTERN char e_cmdmap_repeated[] INIT(= N_("E5521: <Cmd> mapping must end with <CR> before second <Cmd>")); -EXTERN char e_cmdmap_key[] INIT(= N_("E5522: <Cmd> mapping must not include %s key")); +EXTERN char e_cmdmap_repeated[] +INIT(= N_("E5521: <Cmd> mapping must end with <CR> before second <Cmd>")); EXTERN char e_api_error[] INIT(= N_("E5555: API call: %s")); diff --git a/test/functional/ex_cmds/cmd_map_spec.lua b/test/functional/ex_cmds/cmd_map_spec.lua index 64cf53dfa9..dbbfadabd8 100644 --- a/test/functional/ex_cmds/cmd_map_spec.lua +++ b/test/functional/ex_cmds/cmd_map_spec.lua @@ -93,7 +93,7 @@ describe('mappings with <Cmd>', function() {2:E5521: <Cmd> mapping must end with <CR> before second <Cmd>} | ]]) - command('noremap <F3> <Cmd><F3>let x = 2<cr>') + command('noremap <F3> <Cmd>let x = 3') feed('<F3>') screen:expect([[ ^some short lines | @@ -103,22 +103,37 @@ describe('mappings with <Cmd>', function() {1:~ }| {1:~ }| {1:~ }| - {2:E5522: <Cmd> mapping must not include <F3> key} | + {2:E5520: <Cmd> mapping must end with <CR>} | ]]) + eq(0, eval('x')) + end) - command('noremap <F3> <Cmd>let x = 3') + it('allows special keys and modifiers', function() + command('noremap <F3> <Cmd>normal! <Down><CR>') feed('<F3>') screen:expect([[ - ^some short lines | - of test text | + some short lines | + ^of test text | {1:~ }| {1:~ }| {1:~ }| {1:~ }| {1:~ }| - {2:E5520: <Cmd> mapping must end with <CR>} | + | + ]]) + + command('noremap <F3> <Cmd>normal! <C-Right><CR>') + feed('<F3>') + screen:expect([[ + some short lines | + of ^test text | + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + | ]]) - eq(0, eval('x')) end) it('works in various modes and sees correct `mode()` value', function() |