Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c036e87

Browse files
committed
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)
1 parent 5b1c8fe commit c036e87

File tree

12 files changed

+61
-23
lines changed

12 files changed

+61
-23
lines changed

src/ex_docmd.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3671,7 +3671,7 @@ get_address(
36713671
curwin->w_cursor.col = 0;
36723672
searchcmdlen = 0;
36733673
flags = silent ? 0 : SEARCH_HIS | SEARCH_MSG;
3674-
if (!do_search(NULL, c, cmd, 1L, flags, NULL))
3674+
if (!do_search(NULL, c, c, cmd, 1L, flags, NULL))
36753675
{
36763676
curwin->w_cursor = pos;
36773677
cmd = NULL;

src/ex_getln.c

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ set_search_match(pos_T *t)
184184
* May change the last search pattern.
185185
*/
186186
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,
188188
int *skiplen, int *patlen)
189189
{
190190
char_u *cmd;
@@ -210,7 +210,10 @@ do_incsearch_highlighting(int firstc, incsearch_state_T *is_state,
210210
search_last_line = MAXLNUM;
211211

212212
if (firstc == '/' || firstc == '?')
213+
{
214+
*search_delim = firstc;
213215
return TRUE;
216+
}
214217
if (firstc != ':')
215218
return FALSE;
216219

@@ -273,6 +276,7 @@ do_incsearch_highlighting(int firstc, incsearch_state_T *is_state,
273276

274277
p = skipwhite(p);
275278
delim = (delim_optional && vim_isIDc(*p)) ? ' ' : *p++;
279+
*search_delim = delim;
276280
end = skip_regexp(p, delim, p_magic, NULL);
277281

278282
use_last_pat = end == p && *end == delim;
@@ -385,12 +389,13 @@ may_do_incsearch_highlighting(
385389
int next_char;
386390
int use_last_pat;
387391
int did_do_incsearch = is_state->did_incsearch;
392+
int search_delim;
388393

389394
// Parsing range may already set the last search pattern.
390395
// NOTE: must call restore_last_search_pattern() before returning!
391396
save_last_search_pattern();
392397

393-
if (!do_incsearch_highlighting(firstc, is_state, &skiplen, &patlen))
398+
if (!do_incsearch_highlighting(firstc, &search_delim, is_state, &skiplen, &patlen))
394399
{
395400
restore_last_search_pattern();
396401
finish_incsearch_highlighting(FALSE, is_state, TRUE);
@@ -457,7 +462,7 @@ may_do_incsearch_highlighting(
457462
vim_memset(&sia, 0, sizeof(sia));
458463
sia.sa_tm = &tm;
459464
#endif
460-
found = do_search(NULL, firstc == ':' ? '/' : firstc,
465+
found = do_search(NULL, firstc == ':' ? '/' : firstc, search_delim,
461466
ccline.cmdbuff + skiplen, count, search_flags,
462467
#ifdef FEAT_RELTIME
463468
&sia
@@ -565,12 +570,13 @@ may_adjust_incsearch_highlighting(
565570
int search_flags = SEARCH_NOOF;
566571
int i;
567572
int save;
573+
int search_delim;
568574

569575
// Parsing range may already set the last search pattern.
570576
// NOTE: must call restore_last_search_pattern() before returning!
571577
save_last_search_pattern();
572578

573-
if (!do_incsearch_highlighting(firstc, is_state, &skiplen, &patlen))
579+
if (!do_incsearch_highlighting(firstc, &search_delim, is_state, &skiplen, &patlen))
574580
{
575581
restore_last_search_pattern();
576582
return OK;
@@ -581,7 +587,7 @@ may_adjust_incsearch_highlighting(
581587
return FAIL;
582588
}
583589

584-
if (firstc == ccline.cmdbuff[skiplen])
590+
if (search_delim == ccline.cmdbuff[skiplen])
585591
{
586592
pat = last_search_pattern();
587593
skiplen = 0;
@@ -668,13 +674,13 @@ may_adjust_incsearch_highlighting(
668674
static int
669675
may_add_char_to_search(int firstc, int *c, incsearch_state_T *is_state)
670676
{
671-
int skiplen, patlen;
677+
int skiplen, patlen, search_delim;
672678

673679
// Parsing range may already set the last search pattern.
674680
// NOTE: must call restore_last_search_pattern() before returning!
675681
save_last_search_pattern();
676682

677-
if (!do_incsearch_highlighting(firstc, is_state, &skiplen, &patlen))
683+
if (!do_incsearch_highlighting(firstc, &search_delim, is_state, &skiplen, &patlen))
678684
{
679685
restore_last_search_pattern();
680686
return FAIL;
@@ -693,7 +699,7 @@ may_add_char_to_search(int firstc, int *c, incsearch_state_T *is_state)
693699
// the character to lowercase.
694700
if (p_ic && p_scs && !pat_has_uppercase(ccline.cmdbuff + skiplen))
695701
*c = MB_TOLOWER(*c);
696-
if (*c == firstc || vim_strchr((char_u *)(
702+
if (*c == search_delim || vim_strchr((char_u *)(
697703
p_magic ? "\\~^$.*[" : "\\^$"), *c) != NULL)
698704
{
699705
// put a backslash before special characters

src/gui.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5374,15 +5374,15 @@ gui_do_findrepl(
53745374
i = msg_scroll;
53755375
if (down)
53765376
{
5377-
(void)do_search(NULL, '/', ga.ga_data, 1L, searchflags, NULL);
5377+
(void)do_search(NULL, '/', '/', ga.ga_data, 1L, searchflags, NULL);
53785378
}
53795379
else
53805380
{
53815381
// We need to escape '?' if and only if we are searching in the up
53825382
// direction
53835383
p = vim_strsave_escaped(ga.ga_data, (char_u *)"?");
53845384
if (p != NULL)
5385-
(void)do_search(NULL, '?', p, 1L, searchflags, NULL);
5385+
(void)do_search(NULL, '?', '?', p, 1L, searchflags, NULL);
53865386
vim_free(p);
53875387
}
53885388

src/normal.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4304,7 +4304,7 @@ normal_search(
43044304
curwin->w_set_curswant = TRUE;
43054305

43064306
vim_memset(&sia, 0, sizeof(sia));
4307-
i = do_search(cap->oap, dir, pat, cap->count1,
4307+
i = do_search(cap->oap, dir, dir, pat, cap->count1,
43084308
opt | SEARCH_OPT | SEARCH_ECHO | SEARCH_MSG, &sia);
43094309
if (wrapped != NULL)
43104310
*wrapped = sia.sa_wrapped;

src/proto/search.pro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ void set_last_search_pat(char_u *s, int idx, int magic, int setlast);
2424
void last_pat_prog(regmmatch_T *regmatch);
2525
int searchit(win_T *win, buf_T *buf, pos_T *pos, pos_T *end_pos, int dir, char_u *pat, long count, int options, int pat_use, searchit_arg_T *extra_arg);
2626
void set_search_direction(int cdir);
27-
int do_search(oparg_T *oap, int dirc, char_u *pat, long count, int options, searchit_arg_T *sia);
27+
int do_search(oparg_T *oap, int dirc, int search_delim, char_u *pat, long count, int options, searchit_arg_T *sia);
2828
int search_for_exact_line(buf_T *buf, pos_T *pos, int dir, char_u *pat);
2929
int searchc(cmdarg_T *cap, int t_cmd);
3030
pos_T *findmatch(oparg_T *oap, int initc);

src/quickfix.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3197,7 +3197,7 @@ qf_jump_goto_line(
31973197
// Move the cursor to the first line in the buffer
31983198
save_cursor = curwin->w_cursor;
31993199
curwin->w_cursor.lnum = 0;
3200-
if (!do_search(NULL, '/', qf_pattern, (long)1, SEARCH_KEEP, NULL))
3200+
if (!do_search(NULL, '/', '/', qf_pattern, (long)1, SEARCH_KEEP, NULL))
32013201
curwin->w_cursor = save_cursor;
32023202
}
32033203
}

src/search.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1187,6 +1187,7 @@ first_submatch(regmmatch_T *rp)
11871187
do_search(
11881188
oparg_T *oap, // can be NULL
11891189
int dirc, // '/' or '?'
1190+
int search_delim, // the delimiter for the search, e.g. '%' in s%regex%replacement%
11901191
char_u *pat,
11911192
long count,
11921193
int options,
@@ -1285,7 +1286,7 @@ do_search(
12851286
searchstr = pat;
12861287
dircp = NULL;
12871288
// use previous pattern
1288-
if (pat == NULL || *pat == NUL || *pat == dirc)
1289+
if (pat == NULL || *pat == NUL || *pat == search_delim)
12891290
{
12901291
if (spats[RE_SEARCH].pat == NULL) // no previous pattern
12911292
{
@@ -1311,15 +1312,15 @@ do_search(
13111312
* If there is a matching '/' or '?', toss it.
13121313
*/
13131314
ps = strcopy;
1314-
p = skip_regexp(pat, dirc, (int)p_magic, &strcopy);
1315+
p = skip_regexp(pat, search_delim, (int)p_magic, &strcopy);
13151316
if (strcopy != ps)
13161317
{
13171318
// made a copy of "pat" to change "\?" to "?"
13181319
searchcmdlen += (int)(STRLEN(pat) - STRLEN(strcopy));
13191320
pat = strcopy;
13201321
searchstr = strcopy;
13211322
}
1322-
if (*p == dirc)
1323+
if (*p == search_delim)
13231324
{
13241325
dircp = p; // remember where we put the NUL
13251326
*p++ = NUL;
@@ -1525,7 +1526,7 @@ do_search(
15251526
RE_LAST, sia);
15261527

15271528
if (dircp != NULL)
1528-
*dircp = dirc; // restore second '/' or '?' for normal_cmd()
1529+
*dircp = search_delim; // restore second '/' or '?' for normal_cmd()
15291530

15301531
if (!shortmess(SHM_SEARCH)
15311532
&& ((dirc == '/' && LT_POS(pos, curwin->w_cursor))
@@ -1606,6 +1607,7 @@ do_search(
16061607
break;
16071608

16081609
dirc = *++pat;
1610+
search_delim = dirc;
16091611
if (dirc != '?' && dirc != '/')
16101612
{
16111613
retval = 0;

src/spell.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2861,7 +2861,7 @@ ex_spellrepall(exarg_T *eap UNUSED)
28612861
curwin->w_cursor.lnum = 0;
28622862
while (!got_int)
28632863
{
2864-
if (do_search(NULL, '/', frompat, 1L, SEARCH_KEEP, NULL) == 0
2864+
if (do_search(NULL, '/', '/', frompat, 1L, SEARCH_KEEP, NULL) == 0
28652865
|| u_save_cursor() == FAIL)
28662866
break;
28672867

src/tag.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3543,7 +3543,7 @@ jumpto_tag(
35433543
else
35443544
// start search before first line
35453545
curwin->w_cursor.lnum = 0;
3546-
if (do_search(NULL, pbuf[0], pbuf + 1, (long)1,
3546+
if (do_search(NULL, pbuf[0], pbuf[0], pbuf + 1, (long)1,
35473547
search_options, NULL))
35483548
retval = OK;
35493549
else
@@ -3555,7 +3555,7 @@ jumpto_tag(
35553555
* try again, ignore case now
35563556
*/
35573557
p_ic = TRUE;
3558-
if (!do_search(NULL, pbuf[0], pbuf + 1, (long)1,
3558+
if (!do_search(NULL, pbuf[0], pbuf[0], pbuf + 1, (long)1,
35593559
search_options, NULL))
35603560
{
35613561
/*
@@ -3566,13 +3566,13 @@ jumpto_tag(
35663566
cc = *tagp.tagname_end;
35673567
*tagp.tagname_end = NUL;
35683568
sprintf((char *)pbuf, "^%s\\s\\*(", tagp.tagname);
3569-
if (!do_search(NULL, '/', pbuf, (long)1,
3569+
if (!do_search(NULL, '/', '/', pbuf, (long)1,
35703570
search_options, NULL))
35713571
{
35723572
// Guess again: "^char * \<func ("
35733573
sprintf((char *)pbuf, "^\\[#a-zA-Z_]\\.\\*\\<%s\\s\\*(",
35743574
tagp.tagname);
3575-
if (!do_search(NULL, '/', pbuf, (long)1,
3575+
if (!do_search(NULL, '/', '/', pbuf, (long)1,
35763576
search_options, NULL))
35773577
found = 0;
35783578
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
|h+0&#ffffff0|e+1&&|l@1|o|/|t|h|e|r+0&&|e| @8
2+
|~+0#4040ff13&| @18
3+
|~| @18
4+
|:+0#0000000&|%|s|;|e|l@1|o|/|t|h|e> @7

0 commit comments

Comments
 (0)