aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/nvim/ex_getln.c5
-rw-r--r--src/nvim/testdir/test_ex_mode.vim1
-rw-r--r--src/nvim/testdir/test_global.vim30
-rw-r--r--test/functional/legacy/ex_mode_spec.lua2
-rw-r--r--test/functional/legacy/global_spec.lua51
5 files changed, 85 insertions, 4 deletions
diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c
index 8c8f8cec4b..a29063bf91 100644
--- a/src/nvim/ex_getln.c
+++ b/src/nvim/ex_getln.c
@@ -1006,8 +1006,6 @@ static int command_line_check(VimState *state)
// that occurs while typing a command should
// cause the command not to be executed.
- got_int = false; // avoid infinite Ctrl-C loop in Ex mode
-
cursorcmd(); // set the cursor on the right spot
ui_cursor_shape();
return 1;
@@ -1070,7 +1068,8 @@ static int command_line_execute(VimState *state, int key)
// Don't ignore it for the input() function.
if ((s->c == Ctrl_C)
&& s->firstc != '@'
- && !s->break_ctrl_c
+ // do clear got_int in Ex mode to avoid infinite Ctrl-C loop
+ && (!s->break_ctrl_c || exmode_active)
&& !global_busy) {
got_int = false;
}
diff --git a/src/nvim/testdir/test_ex_mode.vim b/src/nvim/testdir/test_ex_mode.vim
index c6bd234e65..2f734cba26 100644
--- a/src/nvim/testdir/test_ex_mode.vim
+++ b/src/nvim/testdir/test_ex_mode.vim
@@ -146,6 +146,7 @@ func Test_Ex_append_in_loop()
call term_sendkeys(buf, "append\<CR>")
call WaitForAssert({-> assert_match(': append', term_getline(buf, 5))}, 1000)
call term_sendkeys(buf, "\<C-C>")
+ " Wait for input to be flushed
call term_wait(buf)
call term_sendkeys(buf, "foo\<CR>")
call WaitForAssert({-> assert_match('foo', term_getline(buf, 5))}, 1000)
diff --git a/src/nvim/testdir/test_global.vim b/src/nvim/testdir/test_global.vim
index feddf85346..947f7efc7c 100644
--- a/src/nvim/testdir/test_global.vim
+++ b/src/nvim/testdir/test_global.vim
@@ -1,4 +1,7 @@
+" Test for :global and :vglobal
+
source check.vim
+source term_util.vim
func Test_yank_put_clipboard()
new
@@ -82,4 +85,31 @@ func Test_wrong_delimiter()
call assert_fails('g x^bxd', 'E146:')
endfunc
+" Test for interrupting :global using Ctrl-C
+func Test_interrupt_global()
+ CheckRunVimInTerminal
+ let lines =<< trim END
+ cnoremap ; <Cmd>sleep 10<CR>
+ call setline(1, repeat(['foo'], 5))
+ END
+ call writefile(lines, 'Xtest_interrupt_global')
+ let buf = RunVimInTerminal('-S Xtest_interrupt_global', {'rows': 6})
+
+ call term_sendkeys(buf, ":g/foo/norm :\<C-V>;\<CR>")
+ " Wait for :sleep to start
+ call term_wait(buf)
+ call term_sendkeys(buf, "\<C-C>")
+ call WaitForAssert({-> assert_match('Interrupted', term_getline(buf, 6))}, 1000)
+
+ " Also test in Ex mode
+ call term_sendkeys(buf, "gQg/foo/norm :\<C-V>;\<CR>")
+ " Wait for :sleep to start
+ call term_wait(buf)
+ call term_sendkeys(buf, "\<C-C>")
+ call WaitForAssert({-> assert_match('Interrupted', term_getline(buf, 5))}, 1000)
+
+ call StopVimInTerminal(buf)
+ call delete('Xtest_interrupt_global')
+endfunc
+
" vim: shiftwidth=2 sts=2 expandtab
diff --git a/test/functional/legacy/ex_mode_spec.lua b/test/functional/legacy/ex_mode_spec.lua
index 59f4a21f5f..a8f54c6939 100644
--- a/test/functional/legacy/ex_mode_spec.lua
+++ b/test/functional/legacy/ex_mode_spec.lua
@@ -143,7 +143,7 @@ describe('Ex mode', function()
^ |
]])
feed('<C-C>')
- sleep(10) -- Wait for Ctrl-C to flush input
+ sleep(10) -- Wait for input to be flushed
feed('foo<CR>')
screen:expect([[
Entering Ex mode. Type "visual" to go to Normal mode. |
diff --git a/test/functional/legacy/global_spec.lua b/test/functional/legacy/global_spec.lua
new file mode 100644
index 0000000000..9f4528530c
--- /dev/null
+++ b/test/functional/legacy/global_spec.lua
@@ -0,0 +1,51 @@
+local helpers = require('test.functional.helpers')(after_each)
+local Screen = require('test.functional.ui.screen')
+local clear = helpers.clear
+local exec = helpers.exec
+local feed = helpers.feed
+local sleep = helpers.sleep
+
+before_each(clear)
+
+describe(':global', function()
+ -- oldtest: Test_interrupt_global()
+ it('can be interrupted using Ctrl-C in cmdline mode vim-patch:9.0.0082', function()
+ local screen = Screen.new(75, 6)
+ screen:set_default_attr_ids({
+ [0] = {bold = true, reverse = true}, -- MsgSeparator
+ [1] = {background = Screen.colors.Red, foreground = Screen.colors.White}, -- ErrorMsg
+ })
+ screen:attach()
+
+ exec([[
+ set nohlsearch noincsearch
+ cnoremap ; <Cmd>sleep 10<CR>
+ call setline(1, repeat(['foo'], 5))
+ ]])
+
+ feed(':g/foo/norm :<C-V>;<CR>')
+ sleep(10) -- Wait for :sleep to start
+ feed('<C-C>')
+ screen:expect([[
+ ^foo |
+ foo |
+ foo |
+ foo |
+ foo |
+ {1:Interrupted} |
+ ]])
+
+ -- Also test in Ex mode
+ feed('gQg/foo/norm :<C-V>;<CR>')
+ sleep(10) -- Wait for :sleep to start
+ feed('<C-C>')
+ screen:expect([[
+ {0: }|
+ Entering Ex mode. Type "visual" to go to Normal mode. |
+ :g/foo/norm :; |
+ |
+ {1:Interrupted} |
+ :^ |
+ ]])
+ end)
+end)