aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAufar Gilbran <aufargilbran@gmail.com>2020-08-19 00:51:24 +0800
committerAufar Gilbran <aufargilbran@gmail.com>2020-09-11 10:37:52 +0800
commite2dc2a6bd751f5614fb7f51a2bd1bc28c3bf4530 (patch)
tree9445c62f3d1ca75f4436261b129aab19d1c3caeb
parentb59c293c25dce6387c939d536c4d7b0f98d83d9e (diff)
downloadrneovim-e2dc2a6bd751f5614fb7f51a2bd1bc28c3bf4530.tar.gz
rneovim-e2dc2a6bd751f5614fb7f51a2bd1bc28c3bf4530.tar.bz2
rneovim-e2dc2a6bd751f5614fb7f51a2bd1bc28c3bf4530.zip
vim-patch:8.1.0351: 'incsearch' for :/foo/s//<Esc> changes last search pattern
Problem: 'incsearch' for :/foo/s//<Esc> changes last search pattern. Solution: Save the last search pattern earlier. https://github.com/vim/vim/commit/198cb66d652d3d8ac16226dcc929a11b0b720151
-rw-r--r--src/nvim/ex_docmd.c16
-rw-r--r--src/nvim/ex_getln.c19
-rw-r--r--src/nvim/testdir/test_search.vim18
3 files changed, 42 insertions, 11 deletions
diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c
index faafd511b1..78d46ad5ee 100644
--- a/src/nvim/ex_docmd.c
+++ b/src/nvim/ex_docmd.c
@@ -2301,6 +2301,7 @@ static void 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 parse_cmd_address(exarg_T *eap, char_u **errormsg)
FUNC_ATTR_NONNULL_ALL
@@ -3683,14 +3684,13 @@ char_u *skip_range(
return (char_u *)cmd;
}
-/*
- * 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.
- *
- * Return MAXLNUM when no Ex address was found.
- */
+// 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.
static linenr_T get_address(exarg_T *eap,
char_u **ptr,
int addr_type, // flag: one of ADDR_LINES, ...
diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c
index e89d835981..b3b81853a3 100644
--- a/src/nvim/ex_getln.c
+++ b/src/nvim/ex_getln.c
@@ -422,13 +422,18 @@ static void may_do_incsearch_highlighting(int firstc, long count,
char_u next_char;
char_u use_last_pat;
+ // Parsing range may already set the last search pattern.
+ save_last_search_pattern();
+
if (!do_incsearch_highlighting(firstc, s, &skiplen, &patlen)) {
+ restore_last_search_pattern();
finish_incsearch_highlighting(false, s, true);
return;
}
// if there is a character waiting, search and redraw later
if (char_avail()) {
+ restore_last_search_pattern();
s->incsearch_postponed = true;
return;
}
@@ -442,7 +447,6 @@ static void may_do_incsearch_highlighting(int firstc, long count,
curwin->w_cursor.lnum = search_first_line;
curwin->w_cursor.col = 0;
}
- save_last_search_pattern();
int i;
// Use the previous pattern for ":s//".
@@ -556,8 +560,13 @@ static void may_do_incsearch_highlighting(int firstc, long count,
static int may_add_char_to_search(int firstc, int *c, incsearch_state_T *s)
{
int skiplen, patlen;
+
+ // Parsing range may already set the last search pattern.
+ save_last_search_pattern();
+
// Add a character from under the cursor for 'incsearch'
if (!do_incsearch_highlighting(firstc, s, &skiplen, &patlen)) {
+ restore_last_search_pattern();
return FAIL;
}
@@ -1431,10 +1440,16 @@ static int may_do_command_line_next_incsearch(int firstc, long count,
bool next_match)
{
int skiplen, patlen;
+
+ // Parsing range may already set the last search pattern.
+ save_last_search_pattern();
+
if (!do_incsearch_highlighting(firstc, s, &skiplen, &patlen)) {
+ restore_last_search_pattern();
return OK;
}
if (patlen == 0 && ccline.cmdbuff[skiplen] == NUL) {
+ restore_last_search_pattern();
return FAIL;
}
@@ -1455,8 +1470,6 @@ static int may_do_command_line_next_incsearch(int firstc, long count,
pat = ccline.cmdbuff + skiplen;
}
- save_last_search_pattern();
-
if (next_match) {
t = s->match_end;
if (lt(s->match_start, s->match_end)) {
diff --git a/src/nvim/testdir/test_search.vim b/src/nvim/testdir/test_search.vim
index baa44da665..dd13baec66 100644
--- a/src/nvim/testdir/test_search.vim
+++ b/src/nvim/testdir/test_search.vim
@@ -783,6 +783,24 @@ func Test_incsearch_vimgrep_dump()
call delete('Xis_vimgrep_script')
endfunc
+func Test_keep_last_search_pattern()
+ throw 'skipped: Nvim does not support test_override()'
+ 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_incsearch_with_change()
if !has('timers') || !exists('+incsearch') || !CanRunVimInTerminal()
throw 'Skipped: cannot make screendumps and/or timers feature and/or incsearch option missing'