mirror of
https://github.com/neovim/neovim.git
synced 2025-09-06 11:28:22 +00:00
feat(mappings): allow special keys and modifiers in <Cmd> mapping
This commit is contained in:
@@ -4861,15 +4861,21 @@ char_u *getcmdkeycmd(int promptc, void *cookie, int indent, bool do_concat)
|
|||||||
// special case to give nicer error message
|
// special case to give nicer error message
|
||||||
emsg(e_cmdmap_repeated);
|
emsg(e_cmdmap_repeated);
|
||||||
aborted = true;
|
aborted = true;
|
||||||
} else if (IS_SPECIAL(c1)) {
|
} else if (c1 == K_SNR) {
|
||||||
if (c1 == K_SNR) {
|
ga_concat(&line_ga, "<SNR>");
|
||||||
ga_concat(&line_ga, "<SNR>");
|
|
||||||
} else {
|
|
||||||
semsg(e_cmdmap_key, get_special_key_name(c1, cmod));
|
|
||||||
aborted = true;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
ga_append(&line_ga, (char)c1);
|
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 {
|
||||||
|
ga_append(&line_ga, (char)c1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cmod = 0;
|
cmod = 0;
|
||||||
|
@@ -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_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_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_repeated[]
|
||||||
EXTERN char e_cmdmap_key[] INIT(= N_("E5522: <Cmd> mapping must not include %s key"));
|
INIT(= N_("E5521: <Cmd> mapping must end with <CR> before second <Cmd>"));
|
||||||
|
|
||||||
EXTERN char e_api_error[] INIT(= N_("E5555: API call: %s"));
|
EXTERN char e_api_error[] INIT(= N_("E5555: API call: %s"));
|
||||||
|
|
||||||
|
@@ -93,19 +93,6 @@ describe('mappings with <Cmd>', function()
|
|||||||
{2:E5521: <Cmd> mapping must end with <CR> before second <Cmd>} |
|
{2:E5521: <Cmd> mapping must end with <CR> before second <Cmd>} |
|
||||||
]])
|
]])
|
||||||
|
|
||||||
command('noremap <F3> <Cmd><F3>let x = 2<cr>')
|
|
||||||
feed('<F3>')
|
|
||||||
screen:expect([[
|
|
||||||
^some short lines |
|
|
||||||
of test text |
|
|
||||||
{1:~ }|
|
|
||||||
{1:~ }|
|
|
||||||
{1:~ }|
|
|
||||||
{1:~ }|
|
|
||||||
{1:~ }|
|
|
||||||
{2:E5522: <Cmd> mapping must not include <F3> key} |
|
|
||||||
]])
|
|
||||||
|
|
||||||
command('noremap <F3> <Cmd>let x = 3')
|
command('noremap <F3> <Cmd>let x = 3')
|
||||||
feed('<F3>')
|
feed('<F3>')
|
||||||
screen:expect([[
|
screen:expect([[
|
||||||
@@ -121,6 +108,34 @@ describe('mappings with <Cmd>', function()
|
|||||||
eq(0, eval('x'))
|
eq(0, eval('x'))
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
it('allows special keys and modifiers', function()
|
||||||
|
command('noremap <F3> <Cmd>normal! <Down><CR>')
|
||||||
|
feed('<F3>')
|
||||||
|
screen:expect([[
|
||||||
|
some short lines |
|
||||||
|
^of test text |
|
||||||
|
{1:~ }|
|
||||||
|
{1:~ }|
|
||||||
|
{1:~ }|
|
||||||
|
{1:~ }|
|
||||||
|
{1:~ }|
|
||||||
|
|
|
||||||
|
]])
|
||||||
|
|
||||||
|
command('noremap <F3> <Cmd>normal! <C-Right><CR>')
|
||||||
|
feed('<F3>')
|
||||||
|
screen:expect([[
|
||||||
|
some short lines |
|
||||||
|
of ^test text |
|
||||||
|
{1:~ }|
|
||||||
|
{1:~ }|
|
||||||
|
{1:~ }|
|
||||||
|
{1:~ }|
|
||||||
|
{1:~ }|
|
||||||
|
|
|
||||||
|
]])
|
||||||
|
end)
|
||||||
|
|
||||||
it('works in various modes and sees correct `mode()` value', function()
|
it('works in various modes and sees correct `mode()` value', function()
|
||||||
-- normal mode
|
-- normal mode
|
||||||
feed('<F3>')
|
feed('<F3>')
|
||||||
|
Reference in New Issue
Block a user