mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
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.
198cb66d65
This commit is contained in:
parent
b59c293c25
commit
e2dc2a6bd7
@ -2301,6 +2301,7 @@ static void free_cmdmod(void)
|
|||||||
|
|
||||||
|
|
||||||
// Parse the address range, if any, in "eap".
|
// Parse the address range, if any, in "eap".
|
||||||
|
// May set the last search pattern.
|
||||||
// Return FAIL and set "errormsg" or return OK.
|
// Return FAIL and set "errormsg" or return OK.
|
||||||
int parse_cmd_address(exarg_T *eap, char_u **errormsg)
|
int parse_cmd_address(exarg_T *eap, char_u **errormsg)
|
||||||
FUNC_ATTR_NONNULL_ALL
|
FUNC_ATTR_NONNULL_ALL
|
||||||
@ -3683,14 +3684,13 @@ char_u *skip_range(
|
|||||||
return (char_u *)cmd;
|
return (char_u *)cmd;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
// 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 the next character after the part that was interpreted.
|
// Set ptr to NULL when an error is encountered.
|
||||||
* 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 MAXLNUM when no Ex address was found.
|
||||||
*/
|
|
||||||
static linenr_T get_address(exarg_T *eap,
|
static linenr_T get_address(exarg_T *eap,
|
||||||
char_u **ptr,
|
char_u **ptr,
|
||||||
int addr_type, // flag: one of ADDR_LINES, ...
|
int addr_type, // flag: one of ADDR_LINES, ...
|
||||||
|
@ -422,13 +422,18 @@ static void may_do_incsearch_highlighting(int firstc, long count,
|
|||||||
char_u next_char;
|
char_u next_char;
|
||||||
char_u use_last_pat;
|
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)) {
|
if (!do_incsearch_highlighting(firstc, s, &skiplen, &patlen)) {
|
||||||
|
restore_last_search_pattern();
|
||||||
finish_incsearch_highlighting(false, s, true);
|
finish_incsearch_highlighting(false, s, true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// if there is a character waiting, search and redraw later
|
// if there is a character waiting, search and redraw later
|
||||||
if (char_avail()) {
|
if (char_avail()) {
|
||||||
|
restore_last_search_pattern();
|
||||||
s->incsearch_postponed = true;
|
s->incsearch_postponed = true;
|
||||||
return;
|
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.lnum = search_first_line;
|
||||||
curwin->w_cursor.col = 0;
|
curwin->w_cursor.col = 0;
|
||||||
}
|
}
|
||||||
save_last_search_pattern();
|
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
// Use the previous pattern for ":s//".
|
// 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)
|
static int may_add_char_to_search(int firstc, int *c, incsearch_state_T *s)
|
||||||
{
|
{
|
||||||
int skiplen, patlen;
|
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'
|
// Add a character from under the cursor for 'incsearch'
|
||||||
if (!do_incsearch_highlighting(firstc, s, &skiplen, &patlen)) {
|
if (!do_incsearch_highlighting(firstc, s, &skiplen, &patlen)) {
|
||||||
|
restore_last_search_pattern();
|
||||||
return FAIL;
|
return FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1431,10 +1440,16 @@ static int may_do_command_line_next_incsearch(int firstc, long count,
|
|||||||
bool next_match)
|
bool next_match)
|
||||||
{
|
{
|
||||||
int skiplen, patlen;
|
int skiplen, patlen;
|
||||||
|
|
||||||
|
// Parsing range may already set the last search pattern.
|
||||||
|
save_last_search_pattern();
|
||||||
|
|
||||||
if (!do_incsearch_highlighting(firstc, s, &skiplen, &patlen)) {
|
if (!do_incsearch_highlighting(firstc, s, &skiplen, &patlen)) {
|
||||||
|
restore_last_search_pattern();
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
if (patlen == 0 && ccline.cmdbuff[skiplen] == NUL) {
|
if (patlen == 0 && ccline.cmdbuff[skiplen] == NUL) {
|
||||||
|
restore_last_search_pattern();
|
||||||
return FAIL;
|
return FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1455,8 +1470,6 @@ static int may_do_command_line_next_incsearch(int firstc, long count,
|
|||||||
pat = ccline.cmdbuff + skiplen;
|
pat = ccline.cmdbuff + skiplen;
|
||||||
}
|
}
|
||||||
|
|
||||||
save_last_search_pattern();
|
|
||||||
|
|
||||||
if (next_match) {
|
if (next_match) {
|
||||||
t = s->match_end;
|
t = s->match_end;
|
||||||
if (lt(s->match_start, s->match_end)) {
|
if (lt(s->match_start, s->match_end)) {
|
||||||
|
@ -783,6 +783,24 @@ func Test_incsearch_vimgrep_dump()
|
|||||||
call delete('Xis_vimgrep_script')
|
call delete('Xis_vimgrep_script')
|
||||||
endfunc
|
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()
|
func Test_incsearch_with_change()
|
||||||
if !has('timers') || !exists('+incsearch') || !CanRunVimInTerminal()
|
if !has('timers') || !exists('+incsearch') || !CanRunVimInTerminal()
|
||||||
throw 'Skipped: cannot make screendumps and/or timers feature and/or incsearch option missing'
|
throw 'Skipped: cannot make screendumps and/or timers feature and/or incsearch option missing'
|
||||||
|
Loading…
Reference in New Issue
Block a user