Mercurial > vim
diff src/search.c @ 12720:37c384802df4 v8.0.1238
patch 8.0.1238: incremental search only shows one match
commit https://github.com/vim/vim/commit/2e51d9a0972080b087d566608472928d5b7b35d7
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Oct 29 16:40:30 2017 +0100
patch 8.0.1238: incremental search only shows one match
Problem: Incremental search only shows one match.
Solution: When 'incsearch' and and 'hlsearch' are both set highlight all
matches. (haya14busa, closes #2198)
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Sun, 29 Oct 2017 16:45:04 +0100 |
parents | 6d3584b60170 |
children | 7749260f261c |
line wrap: on
line diff
--- a/src/search.c +++ b/src/search.c @@ -100,11 +100,14 @@ static int lastc_bytelen = 1; /* >1 for #if defined(FEAT_AUTOCMD) || defined(FEAT_EVAL) || defined(PROTO) /* copy of spats[], for keeping the search patterns while executing autocmds */ static struct spat saved_spats[2]; +#endif +# ifdef FEAT_SEARCH_EXTRA +/* copy of spats[RE_SEARCH], for keeping the search patterns while incremental + * searching */ +static struct spat saved_last_search_spat; static int saved_last_idx = 0; -# ifdef FEAT_SEARCH_EXTRA static int saved_no_hlsearch = 0; # endif -#endif static char_u *mr_pattern = NULL; /* pattern used by search_regcomp() */ #ifdef FEAT_RIGHTLEFT @@ -329,9 +332,9 @@ restore_search_patterns(void) { vim_free(spats[0].pat); spats[0] = saved_spats[0]; -#if defined(FEAT_EVAL) +# if defined(FEAT_EVAL) set_vv_searchforward(); -#endif +# endif vim_free(spats[1].pat); spats[1] = saved_spats[1]; last_idx = saved_last_idx; @@ -360,6 +363,38 @@ free_search_patterns(void) } #endif +#ifdef FEAT_SEARCH_EXTRA +/* + * Save and restore the search pattern for incremental highlight search + * feature. + * + * It's similar but differnt from save_search_patterns() and + * restore_search_patterns(), because the search pattern must be restored when + * cannceling incremental searching even if it's called inside user functions. + */ + void +save_last_search_pattern(void) +{ + saved_last_search_spat = spats[RE_SEARCH]; + if (spats[RE_SEARCH].pat != NULL) + saved_last_search_spat.pat = vim_strsave(spats[RE_SEARCH].pat); + saved_last_idx = last_idx; + saved_no_hlsearch = no_hlsearch; +} + + void +restore_last_search_pattern(void) +{ + vim_free(spats[RE_SEARCH].pat); + spats[RE_SEARCH] = saved_last_search_spat; +# if defined(FEAT_EVAL) + set_vv_searchforward(); +# endif + last_idx = saved_last_idx; + SET_NO_HLSEARCH(saved_no_hlsearch); +} +#endif + /* * Return TRUE when case should be ignored for search pattern "pat". * Uses the 'ignorecase' and 'smartcase' options.