diff options
author | zeertzjq <zeertzjq@outlook.com> | 2022-06-07 12:41:18 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-06-07 12:41:18 +0800 |
commit | 9e442c17eeffca934c1de3674b910458e04c989b (patch) | |
tree | eb5ee68d6e118f1b927a9f3fd6203e4fa673091a | |
parent | ab1f96e1d5ba6d6664eb472c2eaade4f91982734 (diff) | |
download | rneovim-9e442c17eeffca934c1de3674b910458e04c989b.tar.gz rneovim-9e442c17eeffca934c1de3674b910458e04c989b.tar.bz2 rneovim-9e442c17eeffca934c1de3674b910458e04c989b.zip |
fix(input): allow Ctrl-C to interrupt a recursive mapping even if mapped (#18885)
-rw-r--r-- | src/nvim/getchar.c | 10 | ||||
-rw-r--r-- | test/functional/editor/ctrl_c_spec.lua (renamed from test/functional/ex_cmds/ctrl_c_spec.lua) | 19 |
2 files changed, 24 insertions, 5 deletions
diff --git a/src/nvim/getchar.c b/src/nvim/getchar.c index 0aed5c8913..6b716c2e1f 100644 --- a/src/nvim/getchar.c +++ b/src/nvim/getchar.c @@ -2328,19 +2328,19 @@ static int vgetorpeek(bool advance) // try re-mapping. for (;;) { check_end_reg_executing(advance); - // os_breakcheck() can call input_enqueue() - if ((mapped_ctrl_c | curbuf->b_mapped_ctrl_c) & get_real_state()) { - ctrl_c_interrupts = false; - } // os_breakcheck() is slow, don't use it too often when // inside a mapping. But call it each time for typed // characters. if (typebuf.tb_maplen) { line_breakcheck(); } else { + // os_breakcheck() can call input_enqueue() + if ((mapped_ctrl_c | curbuf->b_mapped_ctrl_c) & get_real_state()) { + ctrl_c_interrupts = false; + } os_breakcheck(); // check for CTRL-C + ctrl_c_interrupts = true; } - ctrl_c_interrupts = true; int keylen = 0; if (got_int) { // flush all input diff --git a/test/functional/ex_cmds/ctrl_c_spec.lua b/test/functional/editor/ctrl_c_spec.lua index c2e4bf0fb7..60131bf2a4 100644 --- a/test/functional/ex_cmds/ctrl_c_spec.lua +++ b/test/functional/editor/ctrl_c_spec.lua @@ -72,4 +72,23 @@ describe("CTRL-C (mapped)", function() -- INSERT -- | ]]) end) + + it('interrupts recursive mapping', function() + command('nnoremap <C-C> <Nop>') + command('nmap <F2> <Ignore><F2>') + feed('<F2>') + sleep(10) + feed('foo<C-C>') + -- wait for input buffer to be flushed + sleep(10) + feed('i') + screen:expect([[ + ^ | + ~ | + ~ | + ~ | + ~ | + -- INSERT -- | + ]]) + end) end) |