/*
* Parse the address range, if any, in "eap".
+ * May set the last search pattern.
* Return FAIL and set "errormsg" or return OK.
*/
int
}
/*
- * 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.
*/
/*
* 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,
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;
}
// If there is a character waiting, search and redraw later.
if (char_avail())
{
+ restore_last_search_pattern();
is_state->incsearch_postponed = TRUE;
return;
}
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];
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])
{
else
pat = ccline.cmdbuff + skiplen;
- save_last_search_pattern();
cursor_off();
out_flush();
if (c == Ctrl_G)
{
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)
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