From 621f7b607f977289717f4bea486c96dbe5bf64f3 Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Tue, 29 Sep 2020 07:36:20 -0400 Subject: vim-patch:8.1.1965: search count message is not displayed when using a mapping Problem: The search count message is not displayed when using a mapping. (Gary Johnson) Solution: Ignore cmd_silent for showing the search count. (Christian Brabandt) https://github.com/vim/vim/commit/359ad1a6f92d0d3b4b942ea003fb02dc57bbfc9e --- src/nvim/search.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/nvim/search.c b/src/nvim/search.c index 517db05a40..091068d385 100644 --- a/src/nvim/search.c +++ b/src/nvim/search.c @@ -1155,8 +1155,8 @@ int do_search( pat = p; /* put pat after search command */ } - if ((options & SEARCH_ECHO) && messaging() - && !cmd_silent && msg_silent == 0) { + if ((options & SEARCH_ECHO) && messaging() && !msg_silent + && (!cmd_silent || !shortmess(SHM_SEARCHCOUNT))) { char_u *trunc; char_u off_buf[40]; size_t off_len = 0; @@ -1165,7 +1165,8 @@ int do_search( msg_start(); // Get the offset, so we know how long it is. - if (spats[0].off.line || spats[0].off.end || spats[0].off.off) { + if (!cmd_silent + && (spats[0].off.line || spats[0].off.end || spats[0].off.off)) { p = off_buf; // -V507 *p++ = dirc; if (spats[0].off.end) { @@ -1190,14 +1191,14 @@ int do_search( p = searchstr; } - if (!shortmess(SHM_SEARCHCOUNT)) { + if (!shortmess(SHM_SEARCHCOUNT) || cmd_silent) { // Reserve enough space for the search pattern + offset + // search stat. Use all the space available, so that the // search state is right aligned. If there is not enough space // msg_strtrunc() will shorten in the middle. if (ui_has(kUIMessages)) { len = 0; // adjusted below - } else if (msg_scrolled != 0) { + } else if (msg_scrolled != 0 || cmd_silent) { // Use all the columns. len = (Rows - msg_row) * Columns - 1; } else { @@ -1214,11 +1215,13 @@ int do_search( xfree(msgbuf); msgbuf = xmalloc(len); - { - memset(msgbuf, ' ', len); - msgbuf[0] = dirc; - msgbuf[len - 1] = NUL; + memset(msgbuf, ' ', len); + msgbuf[len - 1] = NUL; + // do not fill the msgbuf buffer, if cmd_silent is set, leave it + // empty for the search_stat feature. + if (!cmd_silent) { + msgbuf[0] = dirc; if (utf_iscomposing(utf_ptr2char(p))) { // Use a space to draw the composing char on. msgbuf[1] = ' '; @@ -1362,7 +1365,7 @@ int do_search( // Show [1/15] if 'S' is not in 'shortmess'. if ((options & SEARCH_ECHO) && messaging() - && !(cmd_silent + msg_silent) + && !msg_silent && c != FAIL && !shortmess(SHM_SEARCHCOUNT) && msgbuf != NULL) { -- cgit From 37c6cbc7588717c2e1396779d4d69fb3e3263c2d Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Tue, 29 Sep 2020 19:26:35 -0400 Subject: vim-patch:8.1.1970: search stat space wrong, no test for 8.1.1965 Problem: Search stat space wrong, no test for 8.1.1965. Solution: Fix check for cmd_silent. Add a test. (Christian Brabandt) https://github.com/vim/vim/commit/19e8ac72e9c17b894a9c74cb8f70feb33567033c --- src/nvim/search.c | 2 +- src/nvim/testdir/test_search_stat.vim | 23 ++++++++++++++++++++++- 2 files changed, 23 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/nvim/search.c b/src/nvim/search.c index 091068d385..d379415d62 100644 --- a/src/nvim/search.c +++ b/src/nvim/search.c @@ -1198,7 +1198,7 @@ int do_search( // msg_strtrunc() will shorten in the middle. if (ui_has(kUIMessages)) { len = 0; // adjusted below - } else if (msg_scrolled != 0 || cmd_silent) { + } else if (msg_scrolled != 0 && !cmd_silent) { // Use all the columns. len = (Rows - msg_row) * Columns - 1; } else { diff --git a/src/nvim/testdir/test_search_stat.vim b/src/nvim/testdir/test_search_stat.vim index fa620b4e00..3dd0bec8c9 100644 --- a/src/nvim/testdir/test_search_stat.vim +++ b/src/nvim/testdir/test_search_stat.vim @@ -162,8 +162,29 @@ func! Test_search_stat() let stat = '\[1/2\]' call assert_notmatch(pat .. stat, g:a) - " close the window + " normal, n comes from a silent mapping + " First test a normal mapping, then a silent mapping + call cursor(1,1) + nnoremap n n + let @/ = 'find this' + let pat = '/find this\s\+' + let g:a = execute(':unsilent :norm n') + let g:b = split(g:a, "\n")[-1] + let stat = '\[1/2\]' + call assert_match(pat .. stat, g:b) + nnoremap n n + call cursor(1,1) + let g:a = execute(':unsilent :norm n') + let g:b = split(g:a, "\n")[-1] + let stat = '\[1/2\]' + call assert_notmatch(pat .. stat, g:b) + call assert_match(stat, g:b) + unmap n + + " Clean up set shortmess+=S + + " close the window bwipe! endfunc -- cgit From a307489a79450a0f54282f11203ae68577505ab4 Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Tue, 29 Sep 2020 19:33:01 -0400 Subject: vim-patch:8.1.1980: fix for search stat not tested Problem: Fix for search stat not tested. Solution: Add a screenshot test. (Christian Brabandt) https://github.com/vim/vim/commit/0f63ed33fdd12d8220f7bc7ff91095e7ceed9985 --- src/nvim/testdir/test_search_stat.vim | 38 +++++++++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/nvim/testdir/test_search_stat.vim b/src/nvim/testdir/test_search_stat.vim index 3dd0bec8c9..1188c220e1 100644 --- a/src/nvim/testdir/test_search_stat.vim +++ b/src/nvim/testdir/test_search_stat.vim @@ -1,13 +1,9 @@ " Tests for search_stats, when "S" is not in 'shortmess' -" -" This test is fragile, it might not work interactively, but it works when run -" as test! -source shared.vim source screendump.vim source check.vim -func! Test_search_stat() +func Test_search_stat() new set shortmess-=S " Append 50 lines with text to search for, "foobar" appears 20 times @@ -179,15 +175,45 @@ func! Test_search_stat() let stat = '\[1/2\]' call assert_notmatch(pat .. stat, g:b) call assert_match(stat, g:b) + " Test that the message is not truncated + " it would insert '...' into the output. + call assert_match('^\s\+' .. stat, g:b) unmap n " Clean up set shortmess+=S - " close the window bwipe! endfunc +func! Test_search_stat_screendump() + CheckScreendump + + let lines =<< trim END + set shortmess-=S + " Append 50 lines with text to search for, "foobar" appears 20 times + call append(0, repeat(['foobar', 'foo', 'fooooobar', 'foba', 'foobar'], 20)) + call setline(2, 'find this') + call setline(70, 'find this') + nnoremap n n + let @/ = 'find this' + call cursor(1,1) + norm n + END + call writefile(lines, 'Xsearchstat') + let buf = RunVimInTerminal('-S Xsearchstat', #{rows: 10}) + call term_wait(buf) + call VerifyScreenDump(buf, 'Test_searchstat_1', {}) + + call term_sendkeys(buf, ":nnoremap n n\") + call term_sendkeys(buf, "gg0n") + call term_wait(buf) + call VerifyScreenDump(buf, 'Test_searchstat_2', {}) + + call StopVimInTerminal(buf) + call delete('Xsearchstat') +endfunc + func Test_searchcount_in_statusline() CheckScreendump -- cgit From 83ebe0c9988bd4abeda0f7ca0775d50e050b9e55 Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Tue, 29 Sep 2020 19:45:32 -0400 Subject: vim-patch:8.1.1992: the search stat moves when wrapping at the end of the buffer Problem: The search stat moves when wrapping at the end of the buffer. Solution: Put the "W" in front instead of at the end. https://github.com/vim/vim/commit/16b58ae9f36e9675c34d942f5d5f8c8a7914dbc4 --- src/nvim/search.c | 4 +++- src/nvim/testdir/test_search_stat.vim | 10 +++++----- 2 files changed, 8 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/nvim/search.c b/src/nvim/search.c index d379415d62..a3acf0c27d 100644 --- a/src/nvim/search.c +++ b/src/nvim/search.c @@ -4359,7 +4359,9 @@ static void search_stat(int dirc, pos_T *pos, len = STRLEN(t); if (show_top_bot_msg && len + 2 < SEARCH_STAT_BUF_LEN) { - STRCPY(t + len, " W"); + memmove(t + 2, t, len); + t[0] = 'W'; + t[1] = ' '; len += 2; } diff --git a/src/nvim/testdir/test_search_stat.vim b/src/nvim/testdir/test_search_stat.vim index 1188c220e1..c1957497f4 100644 --- a/src/nvim/testdir/test_search_stat.vim +++ b/src/nvim/testdir/test_search_stat.vim @@ -43,7 +43,7 @@ func Test_search_stat() call assert_match(pat .. stat, g:a) call cursor(line('$'), 1) let g:a = execute(':unsilent :norm! n') - let stat = '\[1/>99\] W' + let stat = 'W \[1/>99\]' call assert_match(pat .. stat, g:a) " Many matches @@ -53,7 +53,7 @@ func Test_search_stat() call assert_match(pat .. stat, g:a) call cursor(1, 1) let g:a = execute(':unsilent :norm! N') - let stat = '\[>99/>99\] W' + let stat = 'W \[>99/>99\]' call assert_match(pat .. stat, g:a) " right-left @@ -85,7 +85,7 @@ func Test_search_stat() call cursor('$',1) let pat = 'raboof/\s\+' let g:a = execute(':unsilent :norm! n') - let stat = '\[20/1\]' + let stat = 'W \[20/1\]' call assert_match(pat .. stat, g:a) call assert_match('search hit BOTTOM, continuing at TOP', g:a) set norl @@ -96,10 +96,10 @@ func Test_search_stat() let @/ = 'foobar' let pat = '?foobar\s\+' let g:a = execute(':unsilent :norm! N') - let stat = '\[20/20\]' + let stat = 'W \[20/20\]' call assert_match(pat .. stat, g:a) call assert_match('search hit TOP, continuing at BOTTOM', g:a) - call assert_match('\[20/20\] W', Screenline(&lines)) + call assert_match('W \[20/20\]', Screenline(&lines)) " normal, no match call cursor(1,1) -- cgit From 0d100032b885f2eedee96fb7ad6dd660943fc5e3 Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Tue, 29 Sep 2020 19:53:00 -0400 Subject: vim-patch:8.2.0840: search match count wrong when only match is in fold Problem: Search match count wrong when only match is in fold. Solution: Update search stats when in a closed fold. (Christian Brabandt, closes vim/vim#6160, closes vim/vim#6152) https://github.com/vim/vim/commit/6cb0726215519fe94103803e4aa77a355384bcf2 --- src/nvim/search.c | 5 ++++- src/nvim/testdir/test_search_stat.vim | 29 +++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/nvim/search.c b/src/nvim/search.c index a3acf0c27d..b053459c7f 100644 --- a/src/nvim/search.c +++ b/src/nvim/search.c @@ -1370,7 +1370,10 @@ int do_search( && !shortmess(SHM_SEARCHCOUNT) && msgbuf != NULL) { search_stat(dirc, &pos, show_top_bot_msg, msgbuf, - (count != 1 || has_offset)); + (count != 1 + || has_offset + || (!(fdo_flags & FDO_SEARCH) + && hasFolding(curwin->w_cursor.lnum, NULL, NULL)))); } // The search command can be followed by a ';' to do another search. diff --git a/src/nvim/testdir/test_search_stat.vim b/src/nvim/testdir/test_search_stat.vim index c1957497f4..11c6489ca2 100644 --- a/src/nvim/testdir/test_search_stat.vim +++ b/src/nvim/testdir/test_search_stat.vim @@ -186,6 +186,35 @@ func Test_search_stat() bwipe! endfunc +func Test_search_stat_foldopen() + CheckScreendump + + let lines =<< trim END + set shortmess-=S + setl foldenable foldmethod=indent foldopen-=search + call append(0, ['if', "\tfoo", "\tfoo", 'endif']) + let @/ = 'foo' + call cursor(1,1) + norm n + END + call writefile(lines, 'Xsearchstat1') + + let buf = RunVimInTerminal('-S Xsearchstat1', #{rows: 10}) + call TermWait(buf) + call VerifyScreenDump(buf, 'Test_searchstat_3', {}) + + call term_sendkeys(buf, "n") + call TermWait(buf) + call VerifyScreenDump(buf, 'Test_searchstat_3', {}) + + call term_sendkeys(buf, "n") + call TermWait(buf) + call VerifyScreenDump(buf, 'Test_searchstat_3', {}) + + call StopVimInTerminal(buf) + call delete('Xsearchstat1') +endfunc + func! Test_search_stat_screendump() CheckScreendump -- cgit