vim-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: vim/vim#17895
closes: vim/vim#17933

c03990d30f

Co-authored-by: Christian Brabandt <cb@256bit.org>
This commit is contained in:
zeertzjq
2025-08-10 08:05:33 +08:00
parent f79430e2ce
commit 1eca030fb2
3 changed files with 200 additions and 0 deletions

View File

@@ -1543,6 +1543,17 @@ static int may_do_command_line_next_incsearch(int firstc, int count, incsearch_s
pat = ccline.cmdbuff + skiplen;
}
bool bslsh = false;
// 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] = (char)(uint8_t)firstc;
bslsh = true;
}
}
if (next_match) {
t = s->match_end;
if (lt(s->match_start, s->match_end)) {
@@ -1566,6 +1577,9 @@ static int may_do_command_line_next_incsearch(int firstc, int count, incsearch_s
RE_SEARCH, NULL);
emsg_off--;
pat[patlen] = save;
if (bslsh) {
pat[patlen - 1] = '\\';
}
ui_busy_stop();
if (found) {
s->search_start = s->match_start;

View File

@@ -731,6 +731,111 @@ describe('search cmdline', function()
feed('<Esc>')
screen:expect(s)
end)
-- oldtest: Test_incsearch_delimiter_ctrlg()
it('incsearch does not include trailing delimiter', function()
screen:try_resize(20, 6)
exec([[
set incsearch hls
call setline(1, ["1 vim inc", "2 vim /", "3 vim /", "4 vim ?", "5 vim ?"])
normal gg
redraw
]])
feed('/')
poke_eventloop()
feed('v')
poke_eventloop()
feed('i')
poke_eventloop()
feed('m')
poke_eventloop()
feed(' ')
poke_eventloop()
feed('/')
poke_eventloop()
feed('<C-G>')
screen:expect([[
1 {10:vim }inc |
2 {2:vim }/ |
3 {10:vim }/ |
4 {10:vim }? |
5 {10:vim }? |
/vim /^ |
]])
feed('<Esc>')
command('5')
feed('?')
poke_eventloop()
feed('v')
poke_eventloop()
feed('i')
poke_eventloop()
feed('m')
poke_eventloop()
feed(' ')
poke_eventloop()
feed('?')
poke_eventloop()
feed('<C-T>')
screen:expect([[
1 {10:vim }inc |
2 {10:vim }/ |
3 {2:vim }/ |
4 {10:vim }? |
5 {10:vim }? |
?vim ?^ |
]])
feed('<Esc>')
feed('/')
poke_eventloop()
feed('v')
poke_eventloop()
feed('i')
poke_eventloop()
feed('m')
poke_eventloop()
feed(' ')
poke_eventloop()
feed('\\/')
poke_eventloop()
feed('<C-G>')
screen:expect([[
1 vim inc |
2 {10:vim /} |
3 {2:vim /} |
4 vim ? |
5 vim ? |
/vim \/^ |
]])
feed('<Esc>')
command('5')
feed('?')
poke_eventloop()
feed('v')
poke_eventloop()
feed('i')
poke_eventloop()
feed('m')
poke_eventloop()
feed(' ')
poke_eventloop()
feed('\\?')
poke_eventloop()
feed('<C-T>')
screen:expect([[
1 vim inc |
2 vim / |
3 vim / |
4 {10:vim ?} |
5 {2:vim ?} |
?vim \?^ |
]])
feed('<Esc>')
end)
end)
describe('Search highlight', function()

View File

@@ -2159,5 +2159,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