comparison src/ex_getln.c @ 14677:7771a1ff8b99 v8.1.0351

patch 8.1.0351: 'incsearch' for :/foo/s//<Esc> changes last search pattern commit https://github.com/vim/vim/commit/198cb66d652d3d8ac16226dcc929a11b0b720151 Author: Bram Moolenaar <Bram@vim.org> Date: Thu Sep 6 21:44:17 2018 +0200 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.
author Christian Brabandt <cb@256bit.org>
date Thu, 06 Sep 2018 21:45:05 +0200
parents f3b183c3d3e2
children 2982a54aa304
comparison
equal deleted inserted replaced
14676:fb44828733f7 14677:7771a1ff8b99
269 } 269 }
270 270
271 /* 271 /*
272 * Return TRUE when 'incsearch' highlighting is to be done. 272 * Return TRUE when 'incsearch' highlighting is to be done.
273 * Sets search_first_line and search_last_line to the address range. 273 * Sets search_first_line and search_last_line to the address range.
274 * May change the last search pattern.
274 */ 275 */
275 static int 276 static int
276 do_incsearch_highlighting(int firstc, incsearch_state_T *is_state, 277 do_incsearch_highlighting(int firstc, incsearch_state_T *is_state,
277 int *skiplen, int *patlen) 278 int *skiplen, int *patlen)
278 { 279 {
468 proftime_T tm; 469 proftime_T tm;
469 #endif 470 #endif
470 int next_char; 471 int next_char;
471 int use_last_pat; 472 int use_last_pat;
472 473
474 // Parsing range may already set the last search pattern.
475 save_last_search_pattern();
476
473 if (!do_incsearch_highlighting(firstc, is_state, &skiplen, &patlen)) 477 if (!do_incsearch_highlighting(firstc, is_state, &skiplen, &patlen))
474 { 478 {
479 restore_last_search_pattern();
475 finish_incsearch_highlighting(FALSE, is_state, TRUE); 480 finish_incsearch_highlighting(FALSE, is_state, TRUE);
476 return; 481 return;
477 } 482 }
478 483
479 // If there is a character waiting, search and redraw later. 484 // If there is a character waiting, search and redraw later.
480 if (char_avail()) 485 if (char_avail())
481 { 486 {
487 restore_last_search_pattern();
482 is_state->incsearch_postponed = TRUE; 488 is_state->incsearch_postponed = TRUE;
483 return; 489 return;
484 } 490 }
485 is_state->incsearch_postponed = FALSE; 491 is_state->incsearch_postponed = FALSE;
486 492
491 { 497 {
492 // start at the first line in the range 498 // start at the first line in the range
493 curwin->w_cursor.lnum = search_first_line; 499 curwin->w_cursor.lnum = search_first_line;
494 curwin->w_cursor.col = 0; 500 curwin->w_cursor.col = 0;
495 } 501 }
496 save_last_search_pattern();
497 502
498 // Use the previous pattern for ":s//". 503 // Use the previous pattern for ":s//".
499 next_char = ccline.cmdbuff[skiplen + patlen]; 504 next_char = ccline.cmdbuff[skiplen + patlen];
500 use_last_pat = patlen == 0 && skiplen > 0 505 use_last_pat = patlen == 0 && skiplen > 0
501 && ccline.cmdbuff[skiplen - 1] == next_char; 506 && ccline.cmdbuff[skiplen - 1] == next_char;
625 char_u *pat; 630 char_u *pat;
626 int search_flags = SEARCH_NOOF; 631 int search_flags = SEARCH_NOOF;
627 int i; 632 int i;
628 int save; 633 int save;
629 634
635 // Parsing range may already set the last search pattern.
636 save_last_search_pattern();
637
630 if (!do_incsearch_highlighting(firstc, is_state, &skiplen, &patlen)) 638 if (!do_incsearch_highlighting(firstc, is_state, &skiplen, &patlen))
639 {
640 restore_last_search_pattern();
631 return OK; 641 return OK;
642 }
632 if (patlen == 0 && ccline.cmdbuff[skiplen] == NUL) 643 if (patlen == 0 && ccline.cmdbuff[skiplen] == NUL)
644 {
645 restore_last_search_pattern();
633 return FAIL; 646 return FAIL;
647 }
634 648
635 if (firstc == ccline.cmdbuff[skiplen]) 649 if (firstc == ccline.cmdbuff[skiplen])
636 { 650 {
637 pat = last_search_pattern(); 651 pat = last_search_pattern();
638 skiplen = 0; 652 skiplen = 0;
639 patlen = (int)STRLEN(pat); 653 patlen = (int)STRLEN(pat);
640 } 654 }
641 else 655 else
642 pat = ccline.cmdbuff + skiplen; 656 pat = ccline.cmdbuff + skiplen;
643 657
644 save_last_search_pattern();
645 cursor_off(); 658 cursor_off();
646 out_flush(); 659 out_flush();
647 if (c == Ctrl_G) 660 if (c == Ctrl_G)
648 { 661 {
649 t = is_state->match_end; 662 t = is_state->match_end;
719 static int 732 static int
720 may_add_char_to_search(int firstc, int *c, incsearch_state_T *is_state) 733 may_add_char_to_search(int firstc, int *c, incsearch_state_T *is_state)
721 { 734 {
722 int skiplen, patlen; 735 int skiplen, patlen;
723 736
737 // Parsing range may already set the last search pattern.
738 save_last_search_pattern();
739
724 if (!do_incsearch_highlighting(firstc, is_state, &skiplen, &patlen)) 740 if (!do_incsearch_highlighting(firstc, is_state, &skiplen, &patlen))
741 {
742 restore_last_search_pattern();
725 return FAIL; 743 return FAIL;
744 }
726 745
727 // Add a character from under the cursor for 'incsearch'. 746 // Add a character from under the cursor for 'incsearch'.
728 if (is_state->did_incsearch) 747 if (is_state->did_incsearch)
729 { 748 {
730 curwin->w_cursor = is_state->match_end; 749 curwin->w_cursor = is_state->match_end;