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)
54acb90d9e
This commit is contained in:
zeertzjq 2022-08-30 06:32:14 +08:00
parent 2c83d7b2dd
commit e6e9879cb3
2 changed files with 14 additions and 1 deletions

View File

@ -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;
}

View File

@ -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=')