Mercurial > vim
comparison src/ex_getln.c @ 19475:5512aa74cb62 v8.2.0295
patch 8.2.0295: highlighting for :s wrong when using different separator
Commit: https://github.com/vim/vim/commit/c036e87bd7001238ab7cc5d9e30e59bbf989a5fd
Author: Bram Moolenaar <Bram@vim.org>
Date: Fri Feb 21 21:30:52 2020 +0100
patch 8.2.0295: highlighting for :s wrong when using different separator
Problem: Highlighting for :s wrong when using different separator.
Solution: Use separat argument for search direction and separator. (Rob
Pilling, closes #5665)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Fri, 21 Feb 2020 21:45:04 +0100 |
parents | 050f5eaa9e50 |
children | d64f403289db |
comparison
equal
deleted
inserted
replaced
19474:3e0b71dd3dc5 | 19475:5512aa74cb62 |
---|---|
182 * Return TRUE when 'incsearch' highlighting is to be done. | 182 * Return TRUE when 'incsearch' highlighting is to be done. |
183 * Sets search_first_line and search_last_line to the address range. | 183 * Sets search_first_line and search_last_line to the address range. |
184 * May change the last search pattern. | 184 * May change the last search pattern. |
185 */ | 185 */ |
186 static int | 186 static int |
187 do_incsearch_highlighting(int firstc, incsearch_state_T *is_state, | 187 do_incsearch_highlighting(int firstc, int *search_delim, incsearch_state_T *is_state, |
188 int *skiplen, int *patlen) | 188 int *skiplen, int *patlen) |
189 { | 189 { |
190 char_u *cmd; | 190 char_u *cmd; |
191 cmdmod_T save_cmdmod = cmdmod; | 191 cmdmod_T save_cmdmod = cmdmod; |
192 char_u *p; | 192 char_u *p; |
208 // by default search all lines | 208 // by default search all lines |
209 search_first_line = 0; | 209 search_first_line = 0; |
210 search_last_line = MAXLNUM; | 210 search_last_line = MAXLNUM; |
211 | 211 |
212 if (firstc == '/' || firstc == '?') | 212 if (firstc == '/' || firstc == '?') |
213 { | |
214 *search_delim = firstc; | |
213 return TRUE; | 215 return TRUE; |
216 } | |
214 if (firstc != ':') | 217 if (firstc != ':') |
215 return FALSE; | 218 return FALSE; |
216 | 219 |
217 ++emsg_off; | 220 ++emsg_off; |
218 vim_memset(&ea, 0, sizeof(ea)); | 221 vim_memset(&ea, 0, sizeof(ea)); |
271 else | 274 else |
272 goto theend; | 275 goto theend; |
273 | 276 |
274 p = skipwhite(p); | 277 p = skipwhite(p); |
275 delim = (delim_optional && vim_isIDc(*p)) ? ' ' : *p++; | 278 delim = (delim_optional && vim_isIDc(*p)) ? ' ' : *p++; |
279 *search_delim = delim; | |
276 end = skip_regexp(p, delim, p_magic, NULL); | 280 end = skip_regexp(p, delim, p_magic, NULL); |
277 | 281 |
278 use_last_pat = end == p && *end == delim; | 282 use_last_pat = end == p && *end == delim; |
279 | 283 |
280 if (end == p && !use_last_pat) | 284 if (end == p && !use_last_pat) |
383 searchit_arg_T sia; | 387 searchit_arg_T sia; |
384 #endif | 388 #endif |
385 int next_char; | 389 int next_char; |
386 int use_last_pat; | 390 int use_last_pat; |
387 int did_do_incsearch = is_state->did_incsearch; | 391 int did_do_incsearch = is_state->did_incsearch; |
392 int search_delim; | |
388 | 393 |
389 // Parsing range may already set the last search pattern. | 394 // Parsing range may already set the last search pattern. |
390 // NOTE: must call restore_last_search_pattern() before returning! | 395 // NOTE: must call restore_last_search_pattern() before returning! |
391 save_last_search_pattern(); | 396 save_last_search_pattern(); |
392 | 397 |
393 if (!do_incsearch_highlighting(firstc, is_state, &skiplen, &patlen)) | 398 if (!do_incsearch_highlighting(firstc, &search_delim, is_state, &skiplen, &patlen)) |
394 { | 399 { |
395 restore_last_search_pattern(); | 400 restore_last_search_pattern(); |
396 finish_incsearch_highlighting(FALSE, is_state, TRUE); | 401 finish_incsearch_highlighting(FALSE, is_state, TRUE); |
397 if (did_do_incsearch && vpeekc() == NUL) | 402 if (did_do_incsearch && vpeekc() == NUL) |
398 // may have skipped a redraw, do it now | 403 // may have skipped a redraw, do it now |
455 ccline.cmdbuff[skiplen + patlen] = NUL; | 460 ccline.cmdbuff[skiplen + patlen] = NUL; |
456 #ifdef FEAT_RELTIME | 461 #ifdef FEAT_RELTIME |
457 vim_memset(&sia, 0, sizeof(sia)); | 462 vim_memset(&sia, 0, sizeof(sia)); |
458 sia.sa_tm = &tm; | 463 sia.sa_tm = &tm; |
459 #endif | 464 #endif |
460 found = do_search(NULL, firstc == ':' ? '/' : firstc, | 465 found = do_search(NULL, firstc == ':' ? '/' : firstc, search_delim, |
461 ccline.cmdbuff + skiplen, count, search_flags, | 466 ccline.cmdbuff + skiplen, count, search_flags, |
462 #ifdef FEAT_RELTIME | 467 #ifdef FEAT_RELTIME |
463 &sia | 468 &sia |
464 #else | 469 #else |
465 NULL | 470 NULL |
563 pos_T t; | 568 pos_T t; |
564 char_u *pat; | 569 char_u *pat; |
565 int search_flags = SEARCH_NOOF; | 570 int search_flags = SEARCH_NOOF; |
566 int i; | 571 int i; |
567 int save; | 572 int save; |
573 int search_delim; | |
568 | 574 |
569 // Parsing range may already set the last search pattern. | 575 // Parsing range may already set the last search pattern. |
570 // NOTE: must call restore_last_search_pattern() before returning! | 576 // NOTE: must call restore_last_search_pattern() before returning! |
571 save_last_search_pattern(); | 577 save_last_search_pattern(); |
572 | 578 |
573 if (!do_incsearch_highlighting(firstc, is_state, &skiplen, &patlen)) | 579 if (!do_incsearch_highlighting(firstc, &search_delim, is_state, &skiplen, &patlen)) |
574 { | 580 { |
575 restore_last_search_pattern(); | 581 restore_last_search_pattern(); |
576 return OK; | 582 return OK; |
577 } | 583 } |
578 if (patlen == 0 && ccline.cmdbuff[skiplen] == NUL) | 584 if (patlen == 0 && ccline.cmdbuff[skiplen] == NUL) |
579 { | 585 { |
580 restore_last_search_pattern(); | 586 restore_last_search_pattern(); |
581 return FAIL; | 587 return FAIL; |
582 } | 588 } |
583 | 589 |
584 if (firstc == ccline.cmdbuff[skiplen]) | 590 if (search_delim == ccline.cmdbuff[skiplen]) |
585 { | 591 { |
586 pat = last_search_pattern(); | 592 pat = last_search_pattern(); |
587 skiplen = 0; | 593 skiplen = 0; |
588 patlen = (int)STRLEN(pat); | 594 patlen = (int)STRLEN(pat); |
589 } | 595 } |
666 * Return OK when jumping to cmdline_not_changed. | 672 * Return OK when jumping to cmdline_not_changed. |
667 */ | 673 */ |
668 static int | 674 static int |
669 may_add_char_to_search(int firstc, int *c, incsearch_state_T *is_state) | 675 may_add_char_to_search(int firstc, int *c, incsearch_state_T *is_state) |
670 { | 676 { |
671 int skiplen, patlen; | 677 int skiplen, patlen, search_delim; |
672 | 678 |
673 // Parsing range may already set the last search pattern. | 679 // Parsing range may already set the last search pattern. |
674 // NOTE: must call restore_last_search_pattern() before returning! | 680 // NOTE: must call restore_last_search_pattern() before returning! |
675 save_last_search_pattern(); | 681 save_last_search_pattern(); |
676 | 682 |
677 if (!do_incsearch_highlighting(firstc, is_state, &skiplen, &patlen)) | 683 if (!do_incsearch_highlighting(firstc, &search_delim, is_state, &skiplen, &patlen)) |
678 { | 684 { |
679 restore_last_search_pattern(); | 685 restore_last_search_pattern(); |
680 return FAIL; | 686 return FAIL; |
681 } | 687 } |
682 restore_last_search_pattern(); | 688 restore_last_search_pattern(); |
691 // If 'ignorecase' and 'smartcase' are set and the | 697 // If 'ignorecase' and 'smartcase' are set and the |
692 // command line has no uppercase characters, convert | 698 // command line has no uppercase characters, convert |
693 // the character to lowercase. | 699 // the character to lowercase. |
694 if (p_ic && p_scs && !pat_has_uppercase(ccline.cmdbuff + skiplen)) | 700 if (p_ic && p_scs && !pat_has_uppercase(ccline.cmdbuff + skiplen)) |
695 *c = MB_TOLOWER(*c); | 701 *c = MB_TOLOWER(*c); |
696 if (*c == firstc || vim_strchr((char_u *)( | 702 if (*c == search_delim || vim_strchr((char_u *)( |
697 p_magic ? "\\~^$.*[" : "\\^$"), *c) != NULL) | 703 p_magic ? "\\~^$.*[" : "\\^$"), *c) != NULL) |
698 { | 704 { |
699 // put a backslash before special characters | 705 // put a backslash before special characters |
700 stuffcharReadbuff(*c); | 706 stuffcharReadbuff(*c); |
701 *c = '\\'; | 707 *c = '\\'; |