commit e6e9879cb3eecf9d5c3f3964259a89dc36f60d52
parent 2c83d7b2ddf74966777e3bb72230a3605b92ffe2
Author: zeertzjq <zeertzjq@outlook.com>
Date: Tue, 30 Aug 2022 06:32:14 +0800
vim-patch:9.0.0320: command line type of CmdlineChange differs from getcmdtype()
Problem: Command line type of CmdlineChange differs from getcmdtype().
Solution: Use the same type. (closes vim/vim#11005)
https://github.com/vim/vim/commit/54acb90d9e672315e3bd13f8dc71f828df97c868
Diffstat:
2 files changed, 14 insertions(+), 1 deletion(-)
diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c
@@ -4042,7 +4042,7 @@ static int set_cmdline_str(const char *str, int pos)
redrawcmd();
// Trigger CmdlineChanged autocommands.
- do_autocmd_cmdlinechanged(ccline.cmdfirstc == NUL ? '-' : ccline.cmdfirstc);
+ do_autocmd_cmdlinechanged(get_cmdline_type());
return 0;
}
diff --git a/src/nvim/testdir/test_cmdline.vim b/src/nvim/testdir/test_cmdline.vim
@@ -2187,9 +2187,13 @@ endfunc
func Test_setcmdline()
func SetText(text, pos)
+ autocmd CmdlineChanged * let g:cmdtype = expand('<afile>')
call assert_equal(0, setcmdline(a:text))
call assert_equal(a:text, getcmdline())
call assert_equal(len(a:text) + 1, getcmdpos())
+ call assert_equal(getcmdtype(), g:cmdtype)
+ unlet g:cmdtype
+ autocmd! CmdlineChanged
call assert_equal(0, setcmdline(a:text, a:pos))
call assert_equal(a:text, getcmdline())
@@ -2205,6 +2209,13 @@ func Test_setcmdline()
call feedkeys(":\<C-R>=SetText('set rtp?', 2)\<CR>\<CR>", 'xt')
call assert_equal('set rtp?', @:)
+ call feedkeys(":let g:str = input('? ')\<CR>", 't')
+ call feedkeys("\<C-R>=SetText('foo', 4)\<CR>\<CR>", 'xt')
+ call assert_equal('foo', g:str)
+ unlet g:str
+
+ delfunc SetText
+
" setcmdline() returns 1 when not editing the command line.
call assert_equal(1, 'foo'->setcmdline())
@@ -2217,6 +2228,8 @@ func Test_setcmdline()
com! -nargs=* -complete=custom,CustomComplete DoCmd :
call feedkeys(":DoCmd \<C-A>\<C-B>\"\<CR>", 'tx')
call assert_equal('"DoCmd January February Mars', @:)
+ delcom DoCmd
+ delfunc CustomComplete
" Called in <expr>
cnoremap <expr>a setcmdline('let foo=')