vim-patch:8.2.2870: CmdlineChange event triggered twice for CTRL-R (#21361)

Problem:    CmdlineChange event triggered twice for CTRL-R.
Solution:   Return CMDLINE_NOT_CHANGED from cmdline_insert_reg().
            (closes vim/vim#8219)

796139ae3a

Cherry-pick Test_cmdline_map_cmdlineChanged() from patch 8.2.2851.

Co-authored-by: Bram Moolenaar <Bram@vim.org>
This commit is contained in:
zeertzjq 2022-12-11 08:48:00 +08:00 committed by GitHub
parent 224473546c
commit 3dadd3aca5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 26 additions and 2 deletions

View File

@ -1609,7 +1609,8 @@ static int command_line_insert_reg(CommandLineState *s)
ccline.special_char = NUL; ccline.special_char = NUL;
redrawcmd(); redrawcmd();
return CMDLINE_CHANGED; // The text has been stuffed, the command line didn't change yet.
return CMDLINE_NOT_CHANGED;
} }
/// Handle the Left and Right mouse clicks in the command-line mode. /// Handle the Left and Right mouse clicks in the command-line mode.

View File

@ -2235,6 +2235,30 @@ func Test_recalling_cmdline()
cunmap <Plug>(save-cmdline) cunmap <Plug>(save-cmdline)
endfunc endfunc
func Test_cmd_map_cmdlineChanged()
let g:log = []
cnoremap <F1> l<Cmd><CR>s
augroup test
autocmd!
autocmd CmdlineChanged : let g:log += [getcmdline()]
augroup END
call feedkeys(":\<F1>\<CR>", 'xt')
call assert_equal(['l', 'ls'], g:log)
let @b = 'b'
cnoremap <F1> a<C-R>b
let g:log = []
call feedkeys(":\<F1>\<CR>", 'xt')
call assert_equal(['a', 'ab'], g:log)
unlet g:log
cunmap <F1>
augroup test
autocmd!
augroup END
endfunc
" Test for the 'suffixes' option " Test for the 'suffixes' option
func Test_suffixes_opt() func Test_suffixes_opt()
call writefile([], 'Xfile') call writefile([], 'Xfile')

View File

@ -223,7 +223,6 @@ describe('cmdline autocommands', function()
eq({'notification', 'CmdlineChanged', {{cmdtype='=', cmdlevel=2}, "1+1"}}, next_msg()) eq({'notification', 'CmdlineChanged', {{cmdtype='=', cmdlevel=2}, "1+1"}}, next_msg())
feed('<cr>') feed('<cr>')
eq({'notification', 'CmdlineLeave', {{cmdtype='=', cmdlevel=2, abort=false}}}, next_msg()) eq({'notification', 'CmdlineLeave', {{cmdtype='=', cmdlevel=2, abort=false}}}, next_msg())
eq({'notification', 'CmdlineChanged', {{cmdtype=':', cmdlevel=1}, "let x = "}}, next_msg())
eq({'notification', 'CmdlineChanged', {{cmdtype=':', cmdlevel=1}, "let x = 2"}}, next_msg()) eq({'notification', 'CmdlineChanged', {{cmdtype=':', cmdlevel=1}, "let x = 2"}}, next_msg())
feed('<cr>') feed('<cr>')
eq({'notification', 'CmdlineLeave', {{cmdtype=':', cmdlevel=1, abort=false}}}, next_msg()) eq({'notification', 'CmdlineLeave', {{cmdtype=':', cmdlevel=1, abort=false}}}, next_msg())