]> granicus.if.org Git - vim/commitdiff
patch 8.1.0351: 'incsearch' for :/foo/s//<Esc> changes last search pattern v8.1.0351
authorBram Moolenaar <Bram@vim.org>
Thu, 6 Sep 2018 19:44:17 +0000 (21:44 +0200)
committerBram Moolenaar <Bram@vim.org>
Thu, 6 Sep 2018 19:44:17 +0000 (21:44 +0200)
Problem:    'incsearch' for :/foo/s//<Esc> changes last search pattern.
Solution:   Save the last search pattern earlier.

src/ex_docmd.c
src/ex_getln.c
src/testdir/test_search.vim
src/version.c

index 5b53785cc51285bd062f07a0fc4f3187f13cdbef..767791776e136f37f7ee9625cef667d37232f2ea 100644 (file)
@@ -2911,6 +2911,7 @@ free_cmdmod(void)
 
 /*
  * Parse the address range, if any, in "eap".
+ * May set the last search pattern.
  * Return FAIL and set "errormsg" or return OK.
  */
     int
@@ -4436,10 +4437,11 @@ skip_range(
 }
 
 /*
- * get a single EX address
+ * Get a single EX address.
  *
  * Set ptr to the next character after the part that was interpreted.
  * Set ptr to NULL when an error is encountered.
+ * This may set the last used search pattern.
  *
  * Return MAXLNUM when no Ex address was found.
  */
index c316e192ad5f92a896f705cb4f610b21b701330d..80f210a5b080e5d82814e8031f18a9d7973ad949 100644 (file)
@@ -271,6 +271,7 @@ set_search_match(pos_T *t)
 /*
  * Return TRUE when 'incsearch' highlighting is to be done.
  * Sets search_first_line and search_last_line to the address range.
+ * May change the last search pattern.
  */
     static int
 do_incsearch_highlighting(int firstc, incsearch_state_T *is_state,
@@ -470,8 +471,12 @@ may_do_incsearch_highlighting(
     int                next_char;
     int                use_last_pat;
 
+    // Parsing range may already set the last search pattern.
+    save_last_search_pattern();
+
     if (!do_incsearch_highlighting(firstc, is_state, &skiplen, &patlen))
     {
+       restore_last_search_pattern();
        finish_incsearch_highlighting(FALSE, is_state, TRUE);
        return;
     }
@@ -479,6 +484,7 @@ may_do_incsearch_highlighting(
     // If there is a character waiting, search and redraw later.
     if (char_avail())
     {
+       restore_last_search_pattern();
        is_state->incsearch_postponed = TRUE;
        return;
     }
@@ -493,7 +499,6 @@ may_do_incsearch_highlighting(
        curwin->w_cursor.lnum = search_first_line;
        curwin->w_cursor.col = 0;
     }
-    save_last_search_pattern();
 
     // Use the previous pattern for ":s//".
     next_char = ccline.cmdbuff[skiplen + patlen];
@@ -627,10 +632,19 @@ may_adjust_incsearch_highlighting(
     int            i;
     int            save;
 
+    // Parsing range may already set the last search pattern.
+    save_last_search_pattern();
+
     if (!do_incsearch_highlighting(firstc, is_state, &skiplen, &patlen))
+    {
+       restore_last_search_pattern();
        return OK;
+    }
     if (patlen == 0 && ccline.cmdbuff[skiplen] == NUL)
+    {
+       restore_last_search_pattern();
        return FAIL;
+    }
 
     if (firstc == ccline.cmdbuff[skiplen])
     {
@@ -641,7 +655,6 @@ may_adjust_incsearch_highlighting(
     else
        pat = ccline.cmdbuff + skiplen;
 
-    save_last_search_pattern();
     cursor_off();
     out_flush();
     if (c == Ctrl_G)
@@ -721,8 +734,14 @@ may_add_char_to_search(int firstc, int *c, incsearch_state_T *is_state)
 {
     int                skiplen, patlen;
 
+    // Parsing range may already set the last search pattern.
+    save_last_search_pattern();
+
     if (!do_incsearch_highlighting(firstc, is_state, &skiplen, &patlen))
+    {
+       restore_last_search_pattern();
        return FAIL;
+    }
 
     // Add a character from under the cursor for 'incsearch'.
     if (is_state->did_incsearch)
index 68dc3ec8e8d0d05f55ba61f75499191dd8d7fbfb..f96e54abe2af584b7cde4a481eb249e5e5e8b433 100644 (file)
@@ -1043,6 +1043,23 @@ func Test_incsearch_vimgrep_dump()
   call delete('Xis_vimgrep_script')
 endfunc
 
+func Test_keep_last_search_pattern()
+  if !exists('+incsearch')
+    return
+  endif
+  new
+  call setline(1, ['foo', 'foo', 'foo'])
+  set incsearch
+  call test_override("char_avail", 1)
+  let @/ = 'bar'
+  call feedkeys(":/foo/s//\<Esc>", 'ntx')
+  call assert_equal('bar', @/)
+
+  bwipe!
+  call test_override("ALL", 0)
+  set noincsearch
+endfunc
+
 func Test_search_undefined_behaviour()
   if !has("terminal")
     return
index 292af60f5340fffc3153d4c01e8c3f723c4cb208..ba1ac1a19c0dd0e8c6889f321b6a9c33bf99cf50 100644 (file)
@@ -794,6 +794,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    351,
 /**/
     350,
 /**/