From 8145620a958dbb5c82cf8f8a37556ee1ea501c6d Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 7 Jul 2024 20:48:25 +0200 Subject: patch 9.1.0543: Behavior of CursorMovedC is strange Problem: Behavior of CursorMovedC is strange. Solution: Also trigger when the cmdline has changed. (zeertzjq) fixes: #15069 closes: #15071 Signed-off-by: zeertzjq Signed-off-by: Christian Brabandt --- runtime/doc/autocmd.txt | 7 +++---- src/ex_getln.c | 9 ++++++++- src/testdir/test_autocmd.vim | 17 +++++++++++++---- src/version.c | 2 ++ 4 files changed, 26 insertions(+), 9 deletions(-) diff --git a/runtime/doc/autocmd.txt b/runtime/doc/autocmd.txt index 34e9535db9..a5dce7db8f 100644 --- a/runtime/doc/autocmd.txt +++ b/runtime/doc/autocmd.txt @@ -1,4 +1,4 @@ -*autocmd.txt* For Vim version 9.1. Last change: 2024 Jul 06 +*autocmd.txt* For Vim version 9.1. Last change: 2024 Jul 07 VIM REFERENCE MANUAL by Bram Moolenaar @@ -751,9 +751,8 @@ CursorMoved After the cursor was moved in Normal or Visual that is slow. *CursorMovedC* CursorMovedC After the cursor was moved in the command - line while the text in the command line hasn't - changed. Be careful not to mess up the - command line, it may cause Vim to lock up. + line. Be careful not to mess up the command + line, it may cause Vim to lock up. is set to a single character, indicating the type of command-line. |cmdwin-char| diff --git a/src/ex_getln.c b/src/ex_getln.c index 51a38e583e..1b3a699a21 100644 --- a/src/ex_getln.c +++ b/src/ex_getln.c @@ -2480,13 +2480,13 @@ cmdline_not_changed: trigger_cmd_autocmd(cmdline_type, EVENT_CURSORMOVEDC); prev_cmdpos = ccline.cmdpos; } + #ifdef FEAT_SEARCH_EXTRA if (!is_state.incsearch_postponed) continue; #endif cmdline_changed: - prev_cmdpos = ccline.cmdpos; #ifdef FEAT_SEARCH_EXTRA // If the window changed incremental search state is not valid. if (is_state.winid != curwin->w_id) @@ -2496,6 +2496,13 @@ cmdline_changed: if (trigger_cmdlinechanged) trigger_cmd_autocmd(cmdline_type, EVENT_CMDLINECHANGED); + // Trigger CursorMovedC autocommands. + if (ccline.cmdpos != prev_cmdpos) + { + trigger_cmd_autocmd(cmdline_type, EVENT_CURSORMOVEDC); + prev_cmdpos = ccline.cmdpos; + } + #ifdef FEAT_SEARCH_EXTRA if (xpc.xp_context == EXPAND_NOTHING && (KeyTyped || vpeekc() == NUL)) may_do_incsearch_highlighting(firstc, count, &is_state); diff --git a/src/testdir/test_autocmd.vim b/src/testdir/test_autocmd.vim index 371abcbd75..bcbddf9789 100644 --- a/src/testdir/test_autocmd.vim +++ b/src/testdir/test_autocmd.vim @@ -2099,21 +2099,30 @@ func Test_Cmdline() au! CursorMovedC : let g:pos += [getcmdpos()] let g:pos = [] + call feedkeys(":foo bar baz\\\\", 'xt') + call assert_equal([2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 9, 5, 1], g:pos) + let g:pos = [] + call feedkeys(":hello\\", 'xt') + call assert_equal([2, 3, 4, 5, 6, 1], g:pos) + let g:pos = [] + call feedkeys(":hello\\", 'xt') + call assert_equal([2, 3, 4, 5, 6, 1], g:pos) + let g:pos = [] call feedkeys(":hello\\=''\\\\", 'xt') - call assert_equal([5, 4, 5], g:pos) + call assert_equal([2, 3, 4, 5, 6, 5, 4, 5], g:pos) let g:pos = [] call feedkeys(":12345678\=setcmdpos(3)??''\\", 'xt') - call assert_equal([3], g:pos) + call assert_equal([2, 3, 4, 5, 6, 7, 8, 9, 3], g:pos) let g:pos = [] call feedkeys(":12345678\=setcmdpos(3)??''\\\", 'xt') - call assert_equal([3, 2], g:pos) + call assert_equal([2, 3, 4, 5, 6, 7, 8, 9, 3, 2], g:pos) au! CursorMovedC " setcmdpos() is no-op inside an autocommand au! CursorMovedC : let g:pos += [getcmdpos()] | call setcmdpos(1) let g:pos = [] call feedkeys(":hello\\\", 'xt') - call assert_equal([5, 4], g:pos) + call assert_equal([2, 3, 4, 5, 6, 5, 4], g:pos) au! CursorMovedC unlet g:entered diff --git a/src/version.c b/src/version.c index dffc63c1f4..6f7c2c05ff 100644 --- a/src/version.c +++ b/src/version.c @@ -704,6 +704,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ +/**/ + 543, /**/ 542, /**/ -- cgit v1.2.3