Skip to content

Commit

Permalink
Merge pull request #18886 from neovim/backport-18885-to-release-0.7
Browse files Browse the repository at this point in the history
[Backport release-0.7] fix(input): allow Ctrl-C to interrupt a recursive mapping even if mapped
  • Loading branch information
zeertzjq committed Jun 7, 2022
2 parents f0f6350 + 1496f42 commit d317cb2
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/nvim/getchar.c
Original file line number Diff line number Diff line change
Expand Up @@ -2184,19 +2184,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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit d317cb2

Please sign in to comment.