Mercurial > vim
comparison src/search.c @ 15091:e8fdc71f3ea0 v8.1.0556
patch 8.1.0556: saving/restoring search patterns share saved last_idx
commit https://github.com/vim/vim/commit/ed8bc78d2386d22656ba1d3e5cf739dd12964dce
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Dec 1 21:08:21 2018 +0100
patch 8.1.0556: saving/restoring search patterns share saved last_idx
Problem: Saving/restoring search patterns share saved last_idx.
Solution: Use a separate saved last_idx for saving search patterns for
functions and incremental search.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sat, 01 Dec 2018 21:15:04 +0100 |
parents | e428882d6ffb |
children | db5d2429bda3 |
comparison
equal
deleted
inserted
replaced
15090:a5a7fa34aa88 | 15091:e8fdc71f3ea0 |
---|---|
91 #endif | 91 #endif |
92 | 92 |
93 /* copy of spats[], for keeping the search patterns while executing autocmds */ | 93 /* copy of spats[], for keeping the search patterns while executing autocmds */ |
94 static struct spat saved_spats[2]; | 94 static struct spat saved_spats[2]; |
95 # ifdef FEAT_SEARCH_EXTRA | 95 # ifdef FEAT_SEARCH_EXTRA |
96 /* copy of spats[RE_SEARCH], for keeping the search patterns while incremental | 96 static int saved_spats_last_idx = 0; |
97 * searching */ | 97 static int saved_spats_no_hlsearch = 0; |
98 static struct spat saved_last_search_spat; | |
99 static int did_save_last_search_spat = 0; | |
100 static int saved_last_idx = 0; | |
101 static int saved_no_hlsearch = 0; | |
102 # endif | 98 # endif |
103 | 99 |
104 static char_u *mr_pattern = NULL; /* pattern used by search_regcomp() */ | 100 static char_u *mr_pattern = NULL; /* pattern used by search_regcomp() */ |
105 #ifdef FEAT_RIGHTLEFT | 101 #ifdef FEAT_RIGHTLEFT |
106 static int mr_pattern_alloced = FALSE; /* mr_pattern was allocated */ | 102 static int mr_pattern_alloced = FALSE; /* mr_pattern was allocated */ |
308 saved_spats[0].pat = vim_strsave(spats[0].pat); | 304 saved_spats[0].pat = vim_strsave(spats[0].pat); |
309 saved_spats[1] = spats[1]; | 305 saved_spats[1] = spats[1]; |
310 if (spats[1].pat != NULL) | 306 if (spats[1].pat != NULL) |
311 saved_spats[1].pat = vim_strsave(spats[1].pat); | 307 saved_spats[1].pat = vim_strsave(spats[1].pat); |
312 #ifdef FEAT_SEARCH_EXTRA | 308 #ifdef FEAT_SEARCH_EXTRA |
313 saved_last_idx = last_idx; | 309 saved_spats_last_idx = last_idx; |
314 saved_no_hlsearch = no_hlsearch; | 310 saved_spats_no_hlsearch = no_hlsearch; |
315 #endif | 311 #endif |
316 } | 312 } |
317 } | 313 } |
318 | 314 |
319 void | 315 void |
327 set_vv_searchforward(); | 323 set_vv_searchforward(); |
328 #endif | 324 #endif |
329 vim_free(spats[1].pat); | 325 vim_free(spats[1].pat); |
330 spats[1] = saved_spats[1]; | 326 spats[1] = saved_spats[1]; |
331 #ifdef FEAT_SEARCH_EXTRA | 327 #ifdef FEAT_SEARCH_EXTRA |
332 last_idx = saved_last_idx; | 328 last_idx = saved_spats_last_idx; |
333 set_no_hlsearch(saved_no_hlsearch); | 329 set_no_hlsearch(saved_spats_no_hlsearch); |
334 #endif | 330 #endif |
335 } | 331 } |
336 } | 332 } |
337 | 333 |
338 #if defined(EXITFREE) || defined(PROTO) | 334 #if defined(EXITFREE) || defined(PROTO) |
352 # endif | 348 # endif |
353 } | 349 } |
354 #endif | 350 #endif |
355 | 351 |
356 #ifdef FEAT_SEARCH_EXTRA | 352 #ifdef FEAT_SEARCH_EXTRA |
353 // copy of spats[RE_SEARCH], for keeping the search patterns while incremental | |
354 // searching | |
355 static struct spat saved_last_search_spat; | |
356 static int did_save_last_search_spat = 0; | |
357 static int saved_last_idx = 0; | |
358 static int saved_no_hlsearch = 0; | |
359 | |
357 /* | 360 /* |
358 * Save and restore the search pattern for incremental highlight search | 361 * Save and restore the search pattern for incremental highlight search |
359 * feature. | 362 * feature. |
360 * | 363 * |
361 * It's similar to but different from save_search_patterns() and | 364 * It's similar to but different from save_search_patterns() and |
573 saved_spats[idx] = spats[0]; | 576 saved_spats[idx] = spats[0]; |
574 if (spats[idx].pat == NULL) | 577 if (spats[idx].pat == NULL) |
575 saved_spats[idx].pat = NULL; | 578 saved_spats[idx].pat = NULL; |
576 else | 579 else |
577 saved_spats[idx].pat = vim_strsave(spats[idx].pat); | 580 saved_spats[idx].pat = vim_strsave(spats[idx].pat); |
578 saved_last_idx = last_idx; | 581 saved_spats_last_idx = last_idx; |
579 } | 582 } |
580 # ifdef FEAT_SEARCH_EXTRA | 583 # ifdef FEAT_SEARCH_EXTRA |
581 /* If 'hlsearch' set and search pat changed: need redraw. */ | 584 /* If 'hlsearch' set and search pat changed: need redraw. */ |
582 if (p_hls && idx == last_idx && !no_hlsearch) | 585 if (p_hls && idx == last_idx && !no_hlsearch) |
583 redraw_all_later(SOME_VALID); | 586 redraw_all_later(SOME_VALID); |