From 9437800d280385c018a99aa0fbe9043e4d7715aa Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 11 Feb 2023 18:44:06 +0800 Subject: vim-patch:9.0.1298: inserting register on the cmdline does not trigger incsearch Problem: Inserting a register on the command line does not trigger incsearch or update hlsearch. Solution: Have cmdline_insert_reg() return CMDLINE_CHANGED when appropriate and handle it correctly. (Ken Takata, closes vim/vim#11960) https://github.com/vim/vim/commit/c4b7dec38292fe1cfad7aa5f244031fc6f7c7a09 Co-authored-by: K.Takata --- src/nvim/ex_getln.c | 16 ++++++++++------ src/nvim/testdir/test_hlsearch.vim | 23 +++++++++++++++++++++++ 2 files changed, 33 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index 6926a36366..d55da46227 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -1598,8 +1598,10 @@ static int command_line_insert_reg(CommandLineState *s) } } + bool literally = false; if (s->c != ESC) { // use ESC to cancel inserting register - cmdline_paste(s->c, i == Ctrl_R, false); + literally = i == Ctrl_R; + cmdline_paste(s->c, literally, false); // When there was a serious error abort getting the // command line. @@ -1624,8 +1626,9 @@ static int command_line_insert_reg(CommandLineState *s) ccline.special_char = NUL; redrawcmd(); - // The text has been stuffed, the command line didn't change yet. - return CMDLINE_NOT_CHANGED; + // The text has been stuffed, the command line didn't change yet, but it + // will change soon. The caller must take care of it. + return literally ? CMDLINE_NOT_CHANGED : CMDLINE_CHANGED; } /// Handle the Left and Right mouse clicks in the command-line mode. @@ -1857,12 +1860,13 @@ static int command_line_handle_key(CommandLineState *s) case Ctrl_R: // insert register switch (command_line_insert_reg(s)) { - case CMDLINE_NOT_CHANGED: - return command_line_not_changed(s); case GOTO_NORMAL_MODE: return 0; // back to cmd mode + case CMDLINE_NOT_CHANGED: + s->is_state.incsearch_postponed = true; + FALLTHROUGH; default: - return command_line_changed(s); + return command_line_not_changed(s); } case Ctrl_D: diff --git a/src/nvim/testdir/test_hlsearch.vim b/src/nvim/testdir/test_hlsearch.vim index cf2791113a..043d378a39 100644 --- a/src/nvim/testdir/test_hlsearch.vim +++ b/src/nvim/testdir/test_hlsearch.vim @@ -1,5 +1,8 @@ " Test for v:hlsearch +source check.vim +source screendump.vim + func Test_hlsearch() new call setline(1, repeat(['aaa'], 10)) @@ -63,3 +66,23 @@ func Test_hlsearch_eol_highlight() set nohlsearch bwipe! endfunc + +func Test_hlsearch_Ctrl_R() + CheckRunVimInTerminal + + let lines =<< trim END + set incsearch hlsearch + let @" = "text" + put + END + call writefile(lines, 'XhlsearchCtrlR', 'D') + let buf = RunVimInTerminal('-S XhlsearchCtrlR', #{rows: 6, cols: 60}) + + call term_sendkeys(buf, "/\\\"") + call VerifyScreenDump(buf, 'Test_hlsearch_ctrlr_1', {}) + + call term_sendkeys(buf, "\") + call StopVimInTerminal(buf) +endfunc + +" vim: shiftwidth=2 sts=2 expandtab -- cgit From f1fcdcc2c43839b037517d1dd7b1a4570eb970a8 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 11 Feb 2023 19:01:43 +0800 Subject: vim-patch:9.0.1299: change for triggering incsearch not sufficiently tested Problem: Change for triggering incsearch not sufficiently tested. Solution: Add a test case. Simplify the code. (closes vim/vim#11971) https://github.com/vim/vim/commit/412e0e4ed903682f352d8ea58ded480930cc664f --- src/nvim/ex_getln.c | 11 +++++------ src/nvim/testdir/test_autocmd.vim | 22 ++++++++++++++++++---- 2 files changed, 23 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index d55da46227..af26fe8a1c 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -1626,9 +1626,9 @@ static int command_line_insert_reg(CommandLineState *s) ccline.special_char = NUL; redrawcmd(); - // The text has been stuffed, the command line didn't change yet, but it - // will change soon. The caller must take care of it. - return literally ? CMDLINE_NOT_CHANGED : CMDLINE_CHANGED; + // With "literally": the command line has already changed. + // Else: the text has been stuffed, but the command line didn't change yet. + return literally ? CMDLINE_CHANGED : CMDLINE_NOT_CHANGED; } /// Handle the Left and Right mouse clicks in the command-line mode. @@ -1862,9 +1862,8 @@ static int command_line_handle_key(CommandLineState *s) switch (command_line_insert_reg(s)) { case GOTO_NORMAL_MODE: return 0; // back to cmd mode - case CMDLINE_NOT_CHANGED: - s->is_state.incsearch_postponed = true; - FALLTHROUGH; + case CMDLINE_CHANGED: + return command_line_changed(s); default: return command_line_not_changed(s); } diff --git a/src/nvim/testdir/test_autocmd.vim b/src/nvim/testdir/test_autocmd.vim index a1a3ba3198..30d30c8b29 100644 --- a/src/nvim/testdir/test_autocmd.vim +++ b/src/nvim/testdir/test_autocmd.vim @@ -1897,17 +1897,15 @@ func Test_Cmdline() call assert_equal(':', g:entered) au! CmdlineChanged + autocmd CmdlineChanged : let g:log += [getcmdline()] + let g:log = [] cnoremap call setcmdline('ls') - autocmd CmdlineChanged : let g:log += [getcmdline()] call feedkeys(":\", 'xt') call assert_equal(['ls'], g:log) - unlet g:log - au! CmdlineChanged cunmap let g:log = [] - autocmd CmdlineChanged : let g:log += [getcmdline()] call feedkeys(":sign \\\\\\\", 'xt') call assert_equal([ \ 's', @@ -1938,6 +1936,22 @@ func Test_Cmdline() \ 'sign unplace', \ ], g:log) set wildmenu& wildoptions& + + let g:log = [] + let @r = 'abc' + call feedkeys(":0\r1\\r2\\r3\", 'xt') + call assert_equal([ + \ '0', + \ '0a', + \ '0ab', + \ '0abc', + \ '0abc1', + \ '0abc1abc', + \ '0abc1abc2', + \ '0abc1abc2abc', + \ '0abc1abc2abc3', + \ ], g:log) + unlet g:log au! CmdlineChanged -- cgit