aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2022-07-15 05:43:27 +0800
committerzeertzjq <zeertzjq@outlook.com>2022-07-27 06:19:43 +0800
commit45e2bbae835fab479f8e900a2f9c7c47ae22caea (patch)
tree4dc2b53c2a36b603c4ebc7a9a4da39191d8781cc
parent49d2256ae5b747830160a1dd1f3f532cf726b394 (diff)
downloadrneovim-45e2bbae835fab479f8e900a2f9c7c47ae22caea.tar.gz
rneovim-45e2bbae835fab479f8e900a2f9c7c47ae22caea.tar.bz2
rneovim-45e2bbae835fab479f8e900a2f9c7c47ae22caea.zip
vim-patch:9.0.0051: using CTRL-C wih :append may hang Vim
Problem: Using CTRL-C wih :append may hang Vim. Solution: Reset got_int. (closes vim/vim#10729, closes vim/vim#10728) https://github.com/vim/vim/commit/f754fe6a3d5384b5146c38a32db6da9d46e00c40
-rw-r--r--src/nvim/ex_getln.c2
-rw-r--r--src/nvim/testdir/test_ex_mode.vim23
-rw-r--r--test/functional/legacy/ex_mode_spec.lua51
3 files changed, 76 insertions, 0 deletions
diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c
index 3038e7bd04..8c8f8cec4b 100644
--- a/src/nvim/ex_getln.c
+++ b/src/nvim/ex_getln.c
@@ -1006,6 +1006,8 @@ 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;
diff --git a/src/nvim/testdir/test_ex_mode.vim b/src/nvim/testdir/test_ex_mode.vim
index c06d143425..c6bd234e65 100644
--- a/src/nvim/testdir/test_ex_mode.vim
+++ b/src/nvim/testdir/test_ex_mode.vim
@@ -135,6 +135,29 @@ func Test_Ex_global()
bwipe!
endfunc
+" Test for pressing Ctrl-C in :append inside a loop in Ex mode
+" This used to hang Vim
+func Test_Ex_append_in_loop()
+ CheckRunVimInTerminal
+ let buf = RunVimInTerminal('', {'rows': 6})
+
+ call term_sendkeys(buf, "gQ")
+ call term_sendkeys(buf, "for i in range(1)\<CR>")
+ call term_sendkeys(buf, "append\<CR>")
+ call WaitForAssert({-> assert_match(': append', term_getline(buf, 5))}, 1000)
+ call term_sendkeys(buf, "\<C-C>")
+ call term_wait(buf)
+ call term_sendkeys(buf, "foo\<CR>")
+ call WaitForAssert({-> assert_match('foo', term_getline(buf, 5))}, 1000)
+ call term_sendkeys(buf, ".\<CR>")
+ call WaitForAssert({-> assert_match('.', term_getline(buf, 5))}, 1000)
+ call term_sendkeys(buf, "endfor\<CR>")
+ call term_sendkeys(buf, "vi\<CR>")
+ call WaitForAssert({-> assert_match('foo', term_getline(buf, 1))}, 1000)
+
+ call StopVimInTerminal(buf)
+endfunc
+
" In Ex-mode, a backslash escapes a newline
func Test_Ex_escape_enter()
call feedkeys("gQlet l = \"a\\\<kEnter>b\"\<cr>vi\<cr>", 'xt')
diff --git a/test/functional/legacy/ex_mode_spec.lua b/test/functional/legacy/ex_mode_spec.lua
index 98f113bbd0..59f4a21f5f 100644
--- a/test/functional/legacy/ex_mode_spec.lua
+++ b/test/functional/legacy/ex_mode_spec.lua
@@ -6,6 +6,7 @@ local eq = helpers.eq
local eval = helpers.eval
local feed = helpers.feed
local meths = helpers.meths
+local sleep = helpers.sleep
before_each(clear)
@@ -122,4 +123,54 @@ describe('Ex mode', function()
|
]])
end)
+
+ it('pressing Ctrl-C in :append inside a loop in Ex mode does not hang', function()
+ local screen = Screen.new(60, 6)
+ screen:set_default_attr_ids({
+ [0] = {bold = true, reverse = true}, -- MsgSeparator
+ [1] = {bold = true, foreground = Screen.colors.Blue}, -- NonText
+ })
+ screen:attach()
+ feed('gQ')
+ feed('for i in range(1)<CR>')
+ feed('append<CR>')
+ screen:expect([[
+ {0: }|
+ Entering Ex mode. Type "visual" to go to Normal mode. |
+ :for i in range(1) |
+ |
+ : append |
+ ^ |
+ ]])
+ feed('<C-C>')
+ sleep(10) -- Wait for Ctrl-C to flush input
+ feed('foo<CR>')
+ screen:expect([[
+ Entering Ex mode. Type "visual" to go to Normal mode. |
+ :for i in range(1) |
+ |
+ : append |
+ foo |
+ ^ |
+ ]])
+ feed('.<CR>')
+ screen:expect([[
+ :for i in range(1) |
+ |
+ : append |
+ foo |
+ . |
+ : ^ |
+ ]])
+ feed('endfor<CR>')
+ feed('vi<CR>')
+ screen:expect([[
+ ^foo |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ |
+ ]])
+ end)
end)