0
0
mirror of https://github.com/vim/vim.git synced 2025-08-26 20:03:41 -04:00

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>
This commit is contained in:
Christian Brabandt 2025-08-09 23:47:01 +02:00
parent c43a0614d4
commit c03990d30f
No known key found for this signature in database
GPG Key ID: F3F92DA383FDDE09
7 changed files with 122 additions and 0 deletions

View File

@ -620,6 +620,7 @@ may_adjust_incsearch_highlighting(
int search_flags = SEARCH_NOOF;
int i;
int save;
int bslsh = FALSE;
int search_delim;
// Parsing range may already set the last search pattern.
@ -652,6 +653,18 @@ may_adjust_incsearch_highlighting(
else
pat = ccline.cmdbuff + skiplen;
// do not search for the search end delimiter,
// unless it is part of the pattern
if (patlen > 2 && firstc == pat[patlen - 1])
{
patlen--;
if (pat[patlen - 1] == '\\')
{
pat[patlen - 1] = firstc;
bslsh = TRUE;
}
}
cursor_off();
out_flush();
if (c == Ctrl_G)
@ -675,6 +688,8 @@ may_adjust_incsearch_highlighting(
pat, patlen, count, search_flags, RE_SEARCH, NULL);
--emsg_off;
pat[patlen] = save;
if (bslsh)
pat[patlen - 1] = '\\';
if (i)
{
is_state->search_start = is_state->match_start;

View File

@ -0,0 +1,6 @@
|1+0&#ffffff0| |v+0&#ffff4012|i|m| |i+0&#ffffff0|n|c| @65
|2| |v+1&&|i|m| |/+0&&| @67
|3| |v+0&#ffff4012|i|m| |/+0&#ffffff0| @67
|4| |v+0&#ffff4012|i|m| |?+0&#ffffff0| @67
|5| |v+0&#ffff4012|i|m| |?+0&#ffffff0| @67
|/|v|i|m| |/> @68

View File

@ -0,0 +1,6 @@
|1+0&#ffffff0| |v+0&#ffff4012|i|m| |i+0&#ffffff0|n|c| @65
|2| |v+0&#ffff4012|i|m| |/+0&#ffffff0| @67
|3| |v+1&&|i|m| |/+0&&| @67
|4| |v+0&#ffff4012|i|m| |?+0&#ffffff0| @67
|5| |v+0&#ffff4012|i|m| |?+0&#ffffff0| @67
|?|v|i|m| |?> @68

View File

@ -0,0 +1,6 @@
|1+0&#ffffff0| |v|i|m| |i|n|c| @65
|2| |v+0&#ffff4012|i|m| |/| +0&#ffffff0@67
|3| |v+1&&|i|m| |/| +0&&@67
|4| |v|i|m| |?| @67
|5| |v|i|m| |?| @67
|/|v|i|m| |\|/> @67

View File

@ -0,0 +1,6 @@
|1+0&#ffffff0| |v|i|m| |i|n|c| @65
|2| |v|i|m| |/| @67
|3| |v|i|m| |/| @67
|4| |v+0&#ffff4012|i|m| |?| +0&#ffffff0@67
|5| |v+1&&|i|m| |?| +0&&@67
|?|v|i|m| |\|?> @67

View File

@ -2254,5 +2254,86 @@ func Test_search_with_invalid_range()
bwipe!
endfunc
func Test_incsearch_delimiter_ctrlg()
CheckOption incsearch
CheckScreendump
CheckRunVimInTerminal
call assert_equal(0, &scrolloff)
call writefile([
\ 'set incsearch hls',
\ 'call setline(1, ["1 vim inc", "2 vim /", "3 vim /", "4 vim ?", "5 vim ?"])',
\ 'normal gg',
\ 'redraw',
\ ], 'Xscript_incsearch_delim', 'D')
let buf = RunVimInTerminal('-S Xscript_incsearch_delim', {'rows': 6})
call term_sendkeys(buf, '/')
sleep 100m
call term_sendkeys(buf, 'v')
sleep 100m
call term_sendkeys(buf, 'i')
sleep 100m
call term_sendkeys(buf, 'm')
sleep 100m
call term_sendkeys(buf, ' ')
sleep 100m
call term_sendkeys(buf, '/')
sleep 100m
call term_sendkeys(buf, "\<C-G>")
call VerifyScreenDump(buf, 'Test_incsearch_delim_01', {})
call term_sendkeys(buf, "\<Esc>")
call term_sendkeys(buf, ":5\<cr>")
call term_sendkeys(buf, '?')
sleep 100m
call term_sendkeys(buf, 'v')
sleep 100m
call term_sendkeys(buf, 'i')
sleep 100m
call term_sendkeys(buf, 'm')
sleep 100m
call term_sendkeys(buf, ' ')
sleep 100m
call term_sendkeys(buf, '?')
sleep 100m
call term_sendkeys(buf, "\<C-T>")
call VerifyScreenDump(buf, 'Test_incsearch_delim_02', {})
call term_sendkeys(buf, "\<Esc>")
call term_sendkeys(buf, '/')
sleep 100m
call term_sendkeys(buf, 'v')
sleep 100m
call term_sendkeys(buf, 'i')
sleep 100m
call term_sendkeys(buf, 'm')
sleep 100m
call term_sendkeys(buf, ' ')
sleep 100m
call term_sendkeys(buf, '\/')
sleep 100m
call term_sendkeys(buf, "\<C-G>")
call VerifyScreenDump(buf, 'Test_incsearch_delim_03', {})
call term_sendkeys(buf, "\<Esc>")
call term_sendkeys(buf, ":5\<cr>")
call term_sendkeys(buf, '?')
sleep 100m
call term_sendkeys(buf, 'v')
sleep 100m
call term_sendkeys(buf, 'i')
sleep 100m
call term_sendkeys(buf, 'm')
sleep 100m
call term_sendkeys(buf, ' ')
sleep 100m
call term_sendkeys(buf, '\?')
sleep 100m
call term_sendkeys(buf, "\<C-T>")
call VerifyScreenDump(buf, 'Test_incsearch_delim_04', {})
call term_sendkeys(buf, "\<Esc>")
call StopVimInTerminal(buf)
endfunc
" vim: shiftwidth=2 sts=2 expandtab

View File

@ -719,6 +719,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
1612,
/**/
1611,
/**/