comparison src/ex_getln.c @ 14687:2982a54aa304 v8.1.0356

patch 8.1.0356: using :s with 'incsearch' prevents CTRL-R CTRL-W commit https://github.com/vim/vim/commit/99f043a57d0be35ef72572b0429cf51525c3cd2b Author: Bram Moolenaar <Bram@vim.org> Date: Sun Sep 9 15:54:14 2018 +0200 patch 8.1.0356: using :s with 'incsearch' prevents CTRL-R CTRL-W Problem: Using :s with 'incsearch' prevents CTRL-R CTRL-W. (Boris Staletic) Solution: When past the pattern put cursor back in the start position. (closes #3413)
author Christian Brabandt <cb@256bit.org>
date Sun, 09 Sep 2018 16:00:07 +0200
parents 7771a1ff8b99
children 0a3b9ecf7cb8
comparison
equal deleted inserted replaced
14686:712062d04112 14687:2982a54aa304
460 int firstc, 460 int firstc,
461 long count, 461 long count,
462 incsearch_state_T *is_state) 462 incsearch_state_T *is_state)
463 { 463 {
464 int skiplen, patlen; 464 int skiplen, patlen;
465 int i; 465 int found; // do_search() result
466 pos_T end_pos; 466 pos_T end_pos;
467 struct cmdline_info save_ccline; 467 struct cmdline_info save_ccline;
468 #ifdef FEAT_RELTIME 468 #ifdef FEAT_RELTIME
469 proftime_T tm; 469 proftime_T tm;
470 #endif 470 #endif
506 && ccline.cmdbuff[skiplen - 1] == next_char; 506 && ccline.cmdbuff[skiplen - 1] == next_char;
507 507
508 // If there is no pattern, don't do anything. 508 // If there is no pattern, don't do anything.
509 if (patlen == 0 && !use_last_pat) 509 if (patlen == 0 && !use_last_pat)
510 { 510 {
511 i = 0; 511 found = 0;
512 set_no_hlsearch(TRUE); // turn off previous highlight 512 set_no_hlsearch(TRUE); // turn off previous highlight
513 redraw_all_later(SOME_VALID); 513 redraw_all_later(SOME_VALID);
514 } 514 }
515 else 515 else
516 { 516 {
526 if (!p_hls) 526 if (!p_hls)
527 search_flags += SEARCH_KEEP; 527 search_flags += SEARCH_KEEP;
528 if (search_first_line != 0) 528 if (search_first_line != 0)
529 search_flags += SEARCH_START; 529 search_flags += SEARCH_START;
530 ccline.cmdbuff[skiplen + patlen] = NUL; 530 ccline.cmdbuff[skiplen + patlen] = NUL;
531 i = do_search(NULL, firstc == ':' ? '/' : firstc, 531 found = do_search(NULL, firstc == ':' ? '/' : firstc,
532 ccline.cmdbuff + skiplen, count, search_flags, 532 ccline.cmdbuff + skiplen, count, search_flags,
533 #ifdef FEAT_RELTIME 533 #ifdef FEAT_RELTIME
534 &tm, NULL 534 &tm, NULL
535 #else 535 #else
536 NULL, NULL 536 NULL, NULL
541 541
542 if (curwin->w_cursor.lnum < search_first_line 542 if (curwin->w_cursor.lnum < search_first_line
543 || curwin->w_cursor.lnum > search_last_line) 543 || curwin->w_cursor.lnum > search_last_line)
544 { 544 {
545 // match outside of address range 545 // match outside of address range
546 i = 0; 546 found = 0;
547 curwin->w_cursor = is_state->search_start; 547 curwin->w_cursor = is_state->search_start;
548 } 548 }
549 549
550 // if interrupted while searching, behave like it failed 550 // if interrupted while searching, behave like it failed
551 if (got_int) 551 if (got_int)
552 { 552 {
553 (void)vpeekc(); // remove <C-C> from input stream 553 (void)vpeekc(); // remove <C-C> from input stream
554 got_int = FALSE; // don't abandon the command line 554 got_int = FALSE; // don't abandon the command line
555 i = 0; 555 found = 0;
556 } 556 }
557 else if (char_avail()) 557 else if (char_avail())
558 // cancelled searching because a char was typed 558 // cancelled searching because a char was typed
559 is_state->incsearch_postponed = TRUE; 559 is_state->incsearch_postponed = TRUE;
560 } 560 }
561 if (i != 0) 561 if (found != 0)
562 highlight_match = TRUE; // highlight position 562 highlight_match = TRUE; // highlight position
563 else 563 else
564 highlight_match = FALSE; // remove highlight 564 highlight_match = FALSE; // remove highlight
565 565
566 // First restore the old curwin values, so the screen is positioned in the 566 // First restore the old curwin values, so the screen is positioned in the
567 // same way as the actual search command. 567 // same way as the actual search command.
568 restore_viewstate(&is_state->old_viewstate); 568 restore_viewstate(&is_state->old_viewstate);
569 changed_cline_bef_curs(); 569 changed_cline_bef_curs();
570 update_topline(); 570 update_topline();
571 571
572 if (i != 0) 572 if (found != 0)
573 { 573 {
574 pos_T save_pos = curwin->w_cursor; 574 pos_T save_pos = curwin->w_cursor;
575 575
576 is_state->match_start = curwin->w_cursor; 576 is_state->match_start = curwin->w_cursor;
577 set_search_match(&curwin->w_cursor); 577 set_search_match(&curwin->w_cursor);
602 save_cmdline(&save_ccline); 602 save_cmdline(&save_ccline);
603 update_screen(SOME_VALID); 603 update_screen(SOME_VALID);
604 restore_cmdline(&save_ccline); 604 restore_cmdline(&save_ccline);
605 restore_last_search_pattern(); 605 restore_last_search_pattern();
606 606
607 // Leave it at the end to make CTRL-R CTRL-W work. 607 // Leave it at the end to make CTRL-R CTRL-W work. But not when beyond the
608 if (i != 0) 608 // end of the pattern, e.g. for ":s/pat/".
609 if (ccline.cmdbuff[skiplen + patlen] != NUL)
610 curwin->w_cursor = is_state->search_start;
611 else if (found != 0)
609 curwin->w_cursor = end_pos; 612 curwin->w_cursor = end_pos;
610 613
611 msg_starthere(); 614 msg_starthere();
612 redrawcmdline(); 615 redrawcmdline();
613 is_state->did_incsearch = TRUE; 616 is_state->did_incsearch = TRUE;