Mercurial > vim
diff src/search.c @ 16776:7d4c814a8554 v8.1.1390
patch 8.1.1390: search stats are off when using count or offset
commit https://github.com/vim/vim/commit/8f46e4c4bde13fd5ad68a6670b79cc462b65fbec
Author: Bram Moolenaar <Bram@vim.org>
Date: Fri May 24 22:08:15 2019 +0200
patch 8.1.1390: search stats are off when using count or offset
Problem: Search stats are off when using count or offset.
Solution: Recompute the stats when needed. (Masato Nishihata, closes https://github.com/vim/vim/issues/4410)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Fri, 24 May 2019 22:15:05 +0200 |
parents | 695d9ef00b03 |
children | fc58fee685e2 |
line wrap: on
line diff
--- a/src/search.c +++ b/src/search.c @@ -26,7 +26,7 @@ static void show_pat_in_path(char_u *, i #ifdef FEAT_VIMINFO static void wvsp_one(FILE *fp, int idx, char *s, int sc); #endif -static void search_stat(int dirc, pos_T *pos, int show_top_bot_msg, char_u *msgbuf); +static void search_stat(int dirc, pos_T *pos, int show_top_bot_msg, char_u *msgbuf, int recompute); /* * This file contains various searching-related routines. These fall into @@ -1219,6 +1219,7 @@ do_search( char_u *ps; char_u *msgbuf = NULL; size_t len; + int has_offset = FALSE; #define SEARCH_STAT_BUF_LEN 12 /* @@ -1550,6 +1551,8 @@ do_search( */ if (!(options & SEARCH_NOOF) || (pat != NULL && *pat == ';')) { + pos_T org_pos = pos; + if (spats[0].off.line) /* Add the offset to the line number. */ { c = pos.lnum + spats[0].off.off; @@ -1581,6 +1584,8 @@ do_search( break; } } + if (!EQUAL_POS(pos, org_pos)) + has_offset = TRUE; } // Show [1/15] if 'S' is not in 'shortmess'. @@ -1590,7 +1595,8 @@ do_search( && c != FAIL && !shortmess(SHM_SEARCHCOUNT) && msgbuf != NULL) - search_stat(dirc, &pos, show_top_bot_msg, msgbuf); + search_stat(dirc, &pos, show_top_bot_msg, msgbuf, + (count != 1 || has_offset)); /* * The search command can be followed by a ';' to do another search. @@ -4915,13 +4921,15 @@ linewhite(linenr_T lnum) /* * Add the search count "[3/19]" to "msgbuf". + * When "recompute" is TRUE always recompute the numbers. */ static void search_stat( int dirc, pos_T *pos, int show_top_bot_msg, - char_u *msgbuf) + char_u *msgbuf, + int recompute) { int save_ws = p_ws; int wraparound = FALSE; @@ -4947,7 +4955,7 @@ search_stat( && MB_STRNICMP(lastpat, spats[last_idx].pat, STRLEN(lastpat)) == 0 && STRLEN(lastpat) == STRLEN(spats[last_idx].pat) && EQUAL_POS(lastpos, curwin->w_cursor) - && lbuf == curbuf) || wraparound || cur < 0 || cur > 99) + && lbuf == curbuf) || wraparound || cur < 0 || cur > 99 || recompute) { cur = 0; cnt = 0;