mirror of
https://github.com/neovim/neovim.git
synced 2025-09-06 03:18:16 +00:00
vim-patch:9.0.0950: the pattern "\_s\zs" matches at EOL (#21192)
Problem: The pattern "\_s\zs" matches at EOL.
Solution: Make the pattern "\_s\zs" match at the start of the next line.
(closes vim/vim#11617)
c96311b5be
Co-authored-by: Bram Moolenaar <Bram@vim.org>
This commit is contained in:
@@ -655,6 +655,8 @@ int searchit(win_T *win, buf_T *buf, pos_T *pos, pos_T *end_pos, Direction dir,
|
|||||||
// match (this is vi compatible) or on the next char.
|
// match (this is vi compatible) or on the next char.
|
||||||
if (dir == FORWARD && at_first_line) {
|
if (dir == FORWARD && at_first_line) {
|
||||||
match_ok = true;
|
match_ok = true;
|
||||||
|
matchcol = col;
|
||||||
|
|
||||||
// When the match starts in a next line it's certainly
|
// When the match starts in a next line it's certainly
|
||||||
// past the start position.
|
// past the start position.
|
||||||
// When match lands on a NUL the cursor will be put
|
// When match lands on a NUL the cursor will be put
|
||||||
@@ -679,20 +681,21 @@ int searchit(win_T *win, buf_T *buf, pos_T *pos, pos_T *end_pos, Direction dir,
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
matchcol = endpos.col;
|
matchcol = endpos.col;
|
||||||
// for empty match (matchcol == matchpos.col): advance one char
|
// for empty match: advance one char
|
||||||
|
if (matchcol == matchpos.col && ptr[matchcol] != NUL) {
|
||||||
|
matchcol += utfc_ptr2len(ptr + matchcol);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// Prepare to start after first matched character.
|
// Advance "matchcol" to the next character.
|
||||||
matchcol = matchpos.col;
|
// This does not use matchpos.col, because
|
||||||
|
// "\zs" may have have set it.
|
||||||
|
if (ptr[matchcol] != NUL) {
|
||||||
|
matchcol += utfc_ptr2len(ptr + matchcol);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (matchcol == matchpos.col && ptr[matchcol] != NUL) {
|
|
||||||
matchcol += utfc_ptr2len(ptr + matchcol);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (matchcol == 0 && (options & SEARCH_START)) {
|
if (matchcol == 0 && (options & SEARCH_START)) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ptr[matchcol] == NUL
|
if (ptr[matchcol] == NUL
|
||||||
|| (nmatched = vim_regexec_multi(®match, win, buf,
|
|| (nmatched = vim_regexec_multi(®match, win, buf,
|
||||||
lnum, matchcol, tm,
|
lnum, matchcol, tm,
|
||||||
|
@@ -1816,7 +1816,7 @@ func Test_search_smartcase_utf8()
|
|||||||
|
|
||||||
set ignorecase& smartcase&
|
set ignorecase& smartcase&
|
||||||
let &encoding = save_enc
|
let &encoding = save_enc
|
||||||
close!
|
bwipe!
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
" Test searching past the end of a file
|
" Test searching past the end of a file
|
||||||
@@ -1825,7 +1825,29 @@ func Test_search_past_eof()
|
|||||||
call setline(1, ['Line'])
|
call setline(1, ['Line'])
|
||||||
exe "normal /\\n\\zs\<CR>"
|
exe "normal /\\n\\zs\<CR>"
|
||||||
call assert_equal([1, 4], [line('.'), col('.')])
|
call assert_equal([1, 4], [line('.'), col('.')])
|
||||||
close!
|
bwipe!
|
||||||
|
endfunc
|
||||||
|
|
||||||
|
" Test setting the start of the match and still finding a next match in the
|
||||||
|
" same line.
|
||||||
|
func Test_search_set_start_same_line()
|
||||||
|
new
|
||||||
|
set cpo-=c
|
||||||
|
|
||||||
|
call setline(1, ['1', '2', '3 .', '4', '5'])
|
||||||
|
exe "normal /\\_s\\zs\\S\<CR>"
|
||||||
|
call assert_equal([2, 1], [line('.'), col('.')])
|
||||||
|
exe 'normal n'
|
||||||
|
call assert_equal([3, 1], [line('.'), col('.')])
|
||||||
|
exe 'normal n'
|
||||||
|
call assert_equal([3, 3], [line('.'), col('.')])
|
||||||
|
exe 'normal n'
|
||||||
|
call assert_equal([4, 1], [line('.'), col('.')])
|
||||||
|
exe 'normal n'
|
||||||
|
call assert_equal([5, 1], [line('.'), col('.')])
|
||||||
|
|
||||||
|
set cpo+=c
|
||||||
|
bwipe!
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
" Test for various search offsets
|
" Test for various search offsets
|
||||||
|
Reference in New Issue
Block a user