]> granicus.if.org Git - vim/commitdiff
patch 8.1.1390: search stats are off when using count or offset v8.1.1390
authorBram Moolenaar <Bram@vim.org>
Fri, 24 May 2019 20:08:15 +0000 (22:08 +0200)
committerBram Moolenaar <Bram@vim.org>
Fri, 24 May 2019 20:08:15 +0000 (22:08 +0200)
Problem:    Search stats are off when using count or offset.
Solution:   Recompute the stats when needed. (Masato Nishihata, closes #4410)

src/search.c
src/testdir/test_search_stat.vim
src/version.c

index bbe370356d295bd1942afc98ab35783564a034ae..313892f70629fc49ffd11ce4eeb910df8aae2fe1 100644 (file)
@@ -26,7 +26,7 @@ static void show_pat_in_path(char_u *, int,
 #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;
index ad46b2d0592ab25313fb190e4b8ca45e177e0698..cf36f3214acb9cf80e968f14e68a45b5e8875d88 100644 (file)
@@ -117,6 +117,25 @@ func! Test_search_stat()
     call assert_false(1)
   endtry
 
+  " with count
+  call cursor(1, 1)
+  let @/ = 'fo*\(bar\?\)\?'
+  let g:a = execute(':unsilent :norm! 2n')
+  let stat = '\[3/50\]'
+  let pat = escape(@/, '()*?'). '\s\+'
+  call assert_match(pat .. stat, g:a)
+  let g:a = execute(':unsilent :norm! 2n')
+  let stat = '\[5/50\]'
+  call assert_match(pat .. stat, g:a)
+
+  " with offset
+  call cursor(1, 1)
+  call feedkeys("/fo*\\(bar\\?\\)\\?/+1\<cr>", 'tx')
+  let g:a = execute(':unsilent :norm! n')
+  let stat = '\[5/50\]'
+  let pat = escape(@/ .. '/+1', '()*?'). '\s\+'
+  call assert_match(pat .. stat, g:a)
+
   " normal, n comes from a mapping
   "     Need to move over more than 64 lines to trigger char_avail(.
   nnoremap n nzv
index 03ad4bcdf0932c42265508680c2803c1cd017b1f..a97163376f5763b1b37db5c897147ee8d0f060ff 100644 (file)
@@ -767,6 +767,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1390,
 /**/
     1389,
 /**/