diff options
-rw-r--r-- | src/nvim/search.c | 21 | ||||
-rw-r--r-- | src/nvim/testdir/test_search_stat.vim | 5 |
2 files changed, 20 insertions, 6 deletions
diff --git a/src/nvim/search.c b/src/nvim/search.c index 9756faff33..2a14afd762 100644 --- a/src/nvim/search.c +++ b/src/nvim/search.c @@ -1055,6 +1055,8 @@ int do_search( * Repeat the search when pattern followed by ';', e.g. "/foo/;?bar". */ for (;; ) { + bool show_top_bot_msg = false; + searchstr = pat; dircp = NULL; /* use previous pattern */ @@ -1261,7 +1263,7 @@ int do_search( if (!shortmess(SHM_SEARCH) && ((dirc == '/' && lt(pos, curwin->w_cursor)) || (dirc == '?' && lt(curwin->w_cursor, pos)))) { - os_delay(500L, false); // leave some time for top_bot_msg + show_top_bot_msg = true; } if (c == FAIL) { @@ -1312,7 +1314,7 @@ int do_search( && c != FAIL && !shortmess(SHM_SEARCHCOUNT) && msgbuf != NULL) { - search_stat(dirc, &pos, msgbuf); + search_stat(dirc, &pos, show_top_bot_msg, msgbuf); } // The search command can be followed by a ';' to do another search. @@ -4196,7 +4198,8 @@ int linewhite(linenr_T lnum) } // Add the search count "[3/19]" to "msgbuf". -static void search_stat(int dirc, pos_T *pos, char_u *msgbuf) +static void search_stat(int dirc, pos_T *pos, + bool show_top_bot_msg, char_u *msgbuf) { int save_ws = p_ws; int wraparound = false; @@ -4256,8 +4259,9 @@ static void search_stat(int dirc, pos_T *pos, char_u *msgbuf) } } if (cur > 0) { -#define STAT_BUF_LEN 10 +#define STAT_BUF_LEN 12 char t[STAT_BUF_LEN] = ""; + int len; if (curwin->w_p_rl && *curwin->w_p_rlc == 's') { if (cur == OUT_OF_TIME) { @@ -4280,7 +4284,14 @@ static void search_stat(int dirc, pos_T *pos, char_u *msgbuf) vim_snprintf(t, STAT_BUF_LEN, "[%d/%d]", cur, cnt); } } - memmove(msgbuf + STRLEN(msgbuf) - STRLEN(t), t, STRLEN(t)); + + len = STRLEN(t); + if (show_top_bot_msg && len + 3 < STAT_BUF_LEN) { + STRCPY(t + len, " W"); + len += 2; + } + + memmove(msgbuf + STRLEN(msgbuf) - len, t, len); if (dirc == '?' && cur == 100) { cur = -1; } diff --git a/src/nvim/testdir/test_search_stat.vim b/src/nvim/testdir/test_search_stat.vim index 37e2fdaef5..57dad81b81 100644 --- a/src/nvim/testdir/test_search_stat.vim +++ b/src/nvim/testdir/test_search_stat.vim @@ -3,6 +3,8 @@ " This test is fragile, it might not work interactively, but it works when run " as test! +source shared.vim + func! Test_search_stat() new set shortmess-=S @@ -79,7 +81,7 @@ func! Test_search_stat() set norl endif - " 9) normal, back at top + " 9) normal, back at bottom call cursor(1,1) let @/ = 'foobar' let pat = '?foobar\s\+' @@ -87,6 +89,7 @@ func! Test_search_stat() let stat = '\[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)) " 10) normal, no match call cursor(1,1) |