mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
vim-patch:8.1.0552: saved last search pattern may not be restored
Problem: Saved last search pattern may not be restored.
Solution: Call restore_last_search_pattern(). Add a check for balancing
saving and restoring the last search pattern.
01a060da74
This commit is contained in:
parent
f7d2e37e36
commit
466ff35dfd
@ -423,6 +423,7 @@ static void may_do_incsearch_highlighting(int firstc, long count,
|
||||
char_u use_last_pat;
|
||||
|
||||
// Parsing range may already set the last search pattern.
|
||||
// NOTE: must call restore_last_search_pattern() before returning!
|
||||
save_last_search_pattern();
|
||||
|
||||
if (!do_incsearch_highlighting(firstc, s, &skiplen, &patlen)) {
|
||||
@ -566,6 +567,7 @@ 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.
|
||||
// NOTE: must call restore_last_search_pattern() before returning!
|
||||
save_last_search_pattern();
|
||||
|
||||
// Add a character from under the cursor for 'incsearch'
|
||||
@ -573,6 +575,7 @@ static int may_add_char_to_search(int firstc, int *c, incsearch_state_T *s)
|
||||
restore_last_search_pattern();
|
||||
return FAIL;
|
||||
}
|
||||
restore_last_search_pattern();
|
||||
|
||||
if (s->did_incsearch) {
|
||||
curwin->w_cursor = s->match_end;
|
||||
@ -1445,6 +1448,7 @@ static int may_do_command_line_next_incsearch(int firstc, long count,
|
||||
int skiplen, patlen;
|
||||
|
||||
// Parsing range may already set the last search pattern.
|
||||
// NOTE: must call restore_last_search_pattern() before returning!
|
||||
save_last_search_pattern();
|
||||
|
||||
if (!do_incsearch_highlighting(firstc, s, &skiplen, &patlen)) {
|
||||
|
@ -99,6 +99,7 @@ static struct spat saved_spats[2];
|
||||
// copy of spats[RE_SEARCH], for keeping the search patterns while incremental
|
||||
// searching
|
||||
static struct spat saved_last_search_spat;
|
||||
static int did_save_last_search_spat = 0;
|
||||
static int saved_last_idx = 0;
|
||||
static bool saved_no_hlsearch = false;
|
||||
|
||||
@ -316,6 +317,12 @@ void free_search_patterns(void)
|
||||
/// cancelling incremental searching even if it's called inside user functions.
|
||||
void save_last_search_pattern(void)
|
||||
{
|
||||
if (did_save_last_search_spat != 0) {
|
||||
IEMSG("did_save_last_search_spat is not zero");
|
||||
} else {
|
||||
did_save_last_search_spat++;
|
||||
}
|
||||
|
||||
saved_last_search_spat = spats[RE_SEARCH];
|
||||
if (spats[RE_SEARCH].pat != NULL) {
|
||||
saved_last_search_spat.pat = vim_strsave(spats[RE_SEARCH].pat);
|
||||
@ -326,8 +333,15 @@ void save_last_search_pattern(void)
|
||||
|
||||
void restore_last_search_pattern(void)
|
||||
{
|
||||
if (did_save_last_search_spat != 1) {
|
||||
IEMSG("did_save_last_search_spat is not one");
|
||||
return;
|
||||
}
|
||||
did_save_last_search_spat--;
|
||||
|
||||
xfree(spats[RE_SEARCH].pat);
|
||||
spats[RE_SEARCH] = saved_last_search_spat;
|
||||
saved_last_search_spat.pat = NULL;
|
||||
set_vv_searchforward();
|
||||
last_idx = saved_last_idx;
|
||||
set_no_hlsearch(saved_no_hlsearch);
|
||||
|
Loading…
Reference in New Issue
Block a user