Skip to content

Commit c03990d

Browse files
committed
patch 9.1.1612: Ctrl-G/Ctrl-T do not ignore the end search delimiter
Problem: Ctrl-G/Ctrl-T does not ignore the end search delimiter (irisjae) Solution: Check if the pattern ends with a search delimiter and ignore it, unless it is part of the pattern. fixes: #17895 closes: #17933 Signed-off-by: Christian Brabandt <cb@256bit.org>
1 parent c43a061 commit c03990d

7 files changed

Lines changed: 122 additions & 0 deletions

src/ex_getln.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -620,6 +620,7 @@ may_adjust_incsearch_highlighting(
620620
int search_flags = SEARCH_NOOF;
621621
int i;
622622
int save;
623+
int bslsh = FALSE;
623624
int search_delim;
624625

625626
// Parsing range may already set the last search pattern.
@@ -652,6 +653,18 @@ may_adjust_incsearch_highlighting(
652653
else
653654
pat = ccline.cmdbuff + skiplen;
654655

656+
// do not search for the search end delimiter,
657+
// unless it is part of the pattern
658+
if (patlen > 2 && firstc == pat[patlen - 1])
659+
{
660+
patlen--;
661+
if (pat[patlen - 1] == '\\')
662+
{
663+
pat[patlen - 1] = firstc;
664+
bslsh = TRUE;
665+
}
666+
}
667+
655668
cursor_off();
656669
out_flush();
657670
if (c == Ctrl_G)
@@ -675,6 +688,8 @@ may_adjust_incsearch_highlighting(
675688
pat, patlen, count, search_flags, RE_SEARCH, NULL);
676689
--emsg_off;
677690
pat[patlen] = save;
691+
if (bslsh)
692+
pat[patlen - 1] = '\\';
678693
if (i)
679694
{
680695
is_state->search_start = is_state->match_start;
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
|1+0&#ffffff0| |v+0&#ffff4012|i|m| |i+0&#ffffff0|n|c| @65
2+
|2| |v+1&&|i|m| |/+0&&| @67
3+
|3| |v+0&#ffff4012|i|m| |/+0&#ffffff0| @67
4+
|4| |v+0&#ffff4012|i|m| |?+0&#ffffff0| @67
5+
|5| |v+0&#ffff4012|i|m| |?+0&#ffffff0| @67
6+
|/|v|i|m| |/> @68
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
|1+0&#ffffff0| |v+0&#ffff4012|i|m| |i+0&#ffffff0|n|c| @65
2+
|2| |v+0&#ffff4012|i|m| |/+0&#ffffff0| @67
3+
|3| |v+1&&|i|m| |/+0&&| @67
4+
|4| |v+0&#ffff4012|i|m| |?+0&#ffffff0| @67
5+
|5| |v+0&#ffff4012|i|m| |?+0&#ffffff0| @67
6+
|?|v|i|m| |?> @68
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
|1+0&#ffffff0| |v|i|m| |i|n|c| @65
2+
|2| |v+0&#ffff4012|i|m| |/| +0&#ffffff0@67
3+
|3| |v+1&&|i|m| |/| +0&&@67
4+
|4| |v|i|m| |?| @67
5+
|5| |v|i|m| |?| @67
6+
|/|v|i|m| |\|/> @67
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
|1+0&#ffffff0| |v|i|m| |i|n|c| @65
2+
|2| |v|i|m| |/| @67
3+
|3| |v|i|m| |/| @67
4+
|4| |v+0&#ffff4012|i|m| |?| +0&#ffffff0@67
5+
|5| |v+1&&|i|m| |?| +0&&@67
6+
|?|v|i|m| |\|?> @67

src/testdir/test_search.vim

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2254,5 +2254,86 @@ func Test_search_with_invalid_range()
22542254
bwipe!
22552255
endfunc
22562256

2257+
func Test_incsearch_delimiter_ctrlg()
2258+
CheckOption incsearch
2259+
CheckScreendump
2260+
CheckRunVimInTerminal
2261+
call assert_equal(0, &scrolloff)
2262+
call writefile([
2263+
\ 'set incsearch hls',
2264+
\ 'call setline(1, ["1 vim inc", "2 vim /", "3 vim /", "4 vim ?", "5 vim ?"])',
2265+
\ 'normal gg',
2266+
\ 'redraw',
2267+
\ ], 'Xscript_incsearch_delim', 'D')
2268+
let buf = RunVimInTerminal('-S Xscript_incsearch_delim', {'rows': 6})
2269+
2270+
call term_sendkeys(buf, '/')
2271+
sleep 100m
2272+
call term_sendkeys(buf, 'v')
2273+
sleep 100m
2274+
call term_sendkeys(buf, 'i')
2275+
sleep 100m
2276+
call term_sendkeys(buf, 'm')
2277+
sleep 100m
2278+
call term_sendkeys(buf, ' ')
2279+
sleep 100m
2280+
call term_sendkeys(buf, '/')
2281+
sleep 100m
2282+
call term_sendkeys(buf, "\<C-G>")
2283+
call VerifyScreenDump(buf, 'Test_incsearch_delim_01', {})
2284+
call term_sendkeys(buf, "\<Esc>")
2285+
2286+
call term_sendkeys(buf, ":5\<cr>")
2287+
call term_sendkeys(buf, '?')
2288+
sleep 100m
2289+
call term_sendkeys(buf, 'v')
2290+
sleep 100m
2291+
call term_sendkeys(buf, 'i')
2292+
sleep 100m
2293+
call term_sendkeys(buf, 'm')
2294+
sleep 100m
2295+
call term_sendkeys(buf, ' ')
2296+
sleep 100m
2297+
call term_sendkeys(buf, '?')
2298+
sleep 100m
2299+
call term_sendkeys(buf, "\<C-T>")
2300+
call VerifyScreenDump(buf, 'Test_incsearch_delim_02', {})
2301+
call term_sendkeys(buf, "\<Esc>")
2302+
2303+
call term_sendkeys(buf, '/')
2304+
sleep 100m
2305+
call term_sendkeys(buf, 'v')
2306+
sleep 100m
2307+
call term_sendkeys(buf, 'i')
2308+
sleep 100m
2309+
call term_sendkeys(buf, 'm')
2310+
sleep 100m
2311+
call term_sendkeys(buf, ' ')
2312+
sleep 100m
2313+
call term_sendkeys(buf, '\/')
2314+
sleep 100m
2315+
call term_sendkeys(buf, "\<C-G>")
2316+
call VerifyScreenDump(buf, 'Test_incsearch_delim_03', {})
2317+
call term_sendkeys(buf, "\<Esc>")
2318+
2319+
call term_sendkeys(buf, ":5\<cr>")
2320+
call term_sendkeys(buf, '?')
2321+
sleep 100m
2322+
call term_sendkeys(buf, 'v')
2323+
sleep 100m
2324+
call term_sendkeys(buf, 'i')
2325+
sleep 100m
2326+
call term_sendkeys(buf, 'm')
2327+
sleep 100m
2328+
call term_sendkeys(buf, ' ')
2329+
sleep 100m
2330+
call term_sendkeys(buf, '\?')
2331+
sleep 100m
2332+
call term_sendkeys(buf, "\<C-T>")
2333+
call VerifyScreenDump(buf, 'Test_incsearch_delim_04', {})
2334+
call term_sendkeys(buf, "\<Esc>")
2335+
2336+
call StopVimInTerminal(buf)
2337+
endfunc
22572338

22582339
" vim: shiftwidth=2 sts=2 expandtab

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -719,6 +719,8 @@ static char *(features[]) =
719719

720720
static int included_patches[] =
721721
{ /* Add new patch number below this line */
722+
/**/
723+
1612,
722724
/**/
723725
1611,
724726
/**/

0 commit comments

Comments
 (0)