From 3dadd3aca5af4d09d0acbb027098b1a2c889e433 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 11 Dec 2022 08:48:00 +0800 Subject: [PATCH] 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) https://github.com/vim/vim/commit/796139ae3ac89e27ee96dce3c7fdb87d8c839f53 Cherry-pick Test_cmdline_map_cmdlineChanged() from patch 8.2.2851. Co-authored-by: Bram Moolenaar --- src/nvim/ex_getln.c | 3 ++- src/nvim/testdir/test_cmdline.vim | 24 ++++++++++++++++++++++++ test/functional/autocmd/cmdline_spec.lua | 1 - 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index 8fd7cb08f0..395cb5d98a 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -1609,7 +1609,8 @@ static int command_line_insert_reg(CommandLineState *s) ccline.special_char = NUL; 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. diff --git a/src/nvim/testdir/test_cmdline.vim b/src/nvim/testdir/test_cmdline.vim index 0ab82e6bcd..b9f32b2db9 100644 --- a/src/nvim/testdir/test_cmdline.vim +++ b/src/nvim/testdir/test_cmdline.vim @@ -2235,6 +2235,30 @@ func Test_recalling_cmdline() cunmap (save-cmdline) endfunc +func Test_cmd_map_cmdlineChanged() + let g:log = [] + cnoremap ls + augroup test + autocmd! + autocmd CmdlineChanged : let g:log += [getcmdline()] + augroup END + + call feedkeys(":\\", 'xt') + call assert_equal(['l', 'ls'], g:log) + + let @b = 'b' + cnoremap ab + let g:log = [] + call feedkeys(":\\", 'xt') + call assert_equal(['a', 'ab'], g:log) + + unlet g:log + cunmap + augroup test + autocmd! + augroup END +endfunc + " Test for the 'suffixes' option func Test_suffixes_opt() call writefile([], 'Xfile') diff --git a/test/functional/autocmd/cmdline_spec.lua b/test/functional/autocmd/cmdline_spec.lua index c96501ead4..60c29170e2 100644 --- a/test/functional/autocmd/cmdline_spec.lua +++ b/test/functional/autocmd/cmdline_spec.lua @@ -223,7 +223,6 @@ describe('cmdline autocommands', function() eq({'notification', 'CmdlineChanged', {{cmdtype='=', cmdlevel=2}, "1+1"}}, next_msg()) feed('') 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()) feed('') eq({'notification', 'CmdlineLeave', {{cmdtype=':', cmdlevel=1, abort=false}}}, next_msg())