aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2022-09-20 20:38:44 +0800
committerzeertzjq <zeertzjq@outlook.com>2022-09-20 21:00:45 +0800
commit9413f7544bcab6951f9a0c26c4b2e1a6dc477c82 (patch)
tree6181a6980bb891bf4c86794d9242d788f4710850
parentae30e388dee08e59c08dffc20c2f5122b8c31249 (diff)
downloadrneovim-9413f7544bcab6951f9a0c26c4b2e1a6dc477c82.tar.gz
rneovim-9413f7544bcab6951f9a0c26c4b2e1a6dc477c82.tar.bz2
rneovim-9413f7544bcab6951f9a0c26c4b2e1a6dc477c82.zip
vim-patch:9.0.0507: cmdline cleared when using :redrawstatus in CmdlineChanged
Problem: Command line cleared when using :redrawstatus in CmdlineChanged autocommand event. Solution: Postpone the redraw. (closes vim/vim#11162) https://github.com/vim/vim/commit/bcd6924245c0e73d8be256282656c06aaf91f17c Cherry-pick Test_redraw_in_autocmd() from Vim patch 8.2.4789.
-rw-r--r--src/nvim/ex_docmd.c8
-rw-r--r--src/nvim/testdir/test_cmdline.vim40
-rw-r--r--test/functional/legacy/cmdline_spec.lua56
3 files changed, 102 insertions, 2 deletions
diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c
index 52841b6021..8390760b55 100644
--- a/src/nvim/ex_docmd.c
+++ b/src/nvim/ex_docmd.c
@@ -6089,13 +6089,17 @@ static void ex_redrawstatus(exarg_T *eap)
int r = RedrawingDisabled;
int p = p_lz;
- RedrawingDisabled = 0;
- p_lz = false;
if (eap->forceit) {
status_redraw_all();
} else {
status_redraw_curbuf();
}
+ if (State & MODE_CMDLINE) {
+ return; // redraw later
+ }
+
+ RedrawingDisabled = 0;
+ p_lz = false;
update_screen(VIsual_active ? UPD_INVERTED : 0);
RedrawingDisabled = r;
p_lz = p;
diff --git a/src/nvim/testdir/test_cmdline.vim b/src/nvim/testdir/test_cmdline.vim
index 7443ff8fa4..faf68d038e 100644
--- a/src/nvim/testdir/test_cmdline.vim
+++ b/src/nvim/testdir/test_cmdline.vim
@@ -127,6 +127,46 @@ func Test_wildmenu_screendump()
call delete('XTest_wildmenu')
endfunc
+func Test_redraw_in_autocmd()
+ CheckScreendump
+
+ let lines =<< trim END
+ set cmdheight=2
+ autocmd CmdlineChanged * redraw
+ END
+ call writefile(lines, 'XTest_redraw', 'D')
+
+ let buf = RunVimInTerminal('-S XTest_redraw', {'rows': 8})
+ call term_sendkeys(buf, ":for i in range(3)\<CR>")
+ call VerifyScreenDump(buf, 'Test_redraw_in_autocmd_1', {})
+
+ call term_sendkeys(buf, "let i =")
+ call VerifyScreenDump(buf, 'Test_redraw_in_autocmd_2', {})
+
+ " clean up
+ call term_sendkeys(buf, "\<CR>")
+ call StopVimInTerminal(buf)
+endfunc
+
+func Test_redrawstatus_in_autocmd()
+ CheckScreendump
+
+ let lines =<< trim END
+ set cmdheight=2
+ autocmd CmdlineChanged * if getcmdline() == 'foobar' | redrawstatus | endif
+ END
+ call writefile(lines, 'XTest_redrawstatus', 'D')
+
+ let buf = RunVimInTerminal('-S XTest_redrawstatus', {'rows': 8})
+ call term_sendkeys(buf, ":echo \"one\\ntwo\\nthree\\nfour\"\<CR>")
+ call term_sendkeys(buf, ":foobar")
+ call VerifyScreenDump(buf, 'Test_redrawstatus_in_autocmd_1', {})
+
+ " clean up
+ call term_sendkeys(buf, "\<CR>")
+ call StopVimInTerminal(buf)
+endfunc
+
func Test_changing_cmdheight()
CheckScreendump
diff --git a/test/functional/legacy/cmdline_spec.lua b/test/functional/legacy/cmdline_spec.lua
index 99d2d0f30e..8ea5754cfa 100644
--- a/test/functional/legacy/cmdline_spec.lua
+++ b/test/functional/legacy/cmdline_spec.lua
@@ -140,6 +140,62 @@ describe('cmdline', function()
:^ |
]])
end)
+
+ -- oldtest: Test_redraw_in_autocmd()
+ it('cmdline cursor position is correct after :redraw with cmdheight=2', function()
+ local screen = Screen.new(30, 6)
+ screen:set_default_attr_ids({
+ [0] = {bold = true, foreground = Screen.colors.Blue}, -- NonText
+ })
+ screen:attach()
+ exec([[
+ set cmdheight=2
+ autocmd CmdlineChanged * redraw
+ ]])
+ feed(':for i in range(3)<CR>')
+ screen:expect([[
+ |
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ :for i in range(3) |
+ : ^ |
+ ]])
+ feed(':let i =')
+ -- Note: this may still be considered broken, ref #18140
+ screen:expect([[
+ |
+ {0:~ }|
+ {0:~ }|
+ {0:~ }|
+ : :let i =^ |
+ |
+ ]])
+ end)
+
+ -- oldtest: Test_redrawstatus_in_autocmd()
+ it(':redrawstatus in cmdline mode', function()
+ local screen = Screen.new(60, 6)
+ screen:set_default_attr_ids({
+ [0] = {bold = true, foreground = Screen.colors.Blue}, -- NonText
+ [1] = {bold = true, reverse = true}, -- MsgSeparator
+ })
+ screen:attach()
+ exec([[
+ set cmdheight=2
+ autocmd CmdlineChanged * if getcmdline() == 'foobar' | redrawstatus | endif
+ ]])
+ feed([[:echo "one\ntwo\nthree\nfour"<CR>]])
+ feed(':foobar')
+ screen:expect([[
+ {1: }|
+ one |
+ two |
+ three |
+ four |
+ :foobar^ |
+ ]])
+ end)
end)
describe('cmdwin', function()