mirror of
https://github.com/neovim/neovim.git
synced 2025-10-08 19:06:31 +00:00
vim-patch:8.0.0627: "gn" selects only one character with 'nowrapscan' (#8632)
Problem: When 'wrapscan' is off "gn" does not select the whole pattern when
it's the last one in the text. (KeyboardFire)
Solution: Check if the search fails. (Christian Brabandt, closes vim/vim#1683)
add8dce38d
This commit is contained in:

committed by
Justin M. Keyes

parent
bf6048e81d
commit
3d688cc25d
@@ -3966,8 +3966,8 @@ current_search(
|
|||||||
orig_pos = pos = curwin->w_cursor;
|
orig_pos = pos = curwin->w_cursor;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Is the pattern is zero-width? */
|
// Is the pattern is zero-width?
|
||||||
int one_char = is_one_char(spats[last_idx].pat, true);
|
int one_char = is_one_char(spats[last_idx].pat, true, &curwin->w_cursor);
|
||||||
if (one_char == -1) {
|
if (one_char == -1) {
|
||||||
p_ws = old_p_ws;
|
p_ws = old_p_ws;
|
||||||
return FAIL; /* pattern not found */
|
return FAIL; /* pattern not found */
|
||||||
@@ -4015,9 +4015,13 @@ current_search(
|
|||||||
int flags = forward ? SEARCH_END : 0;
|
int flags = forward ? SEARCH_END : 0;
|
||||||
pos_T start_pos = pos;
|
pos_T start_pos = pos;
|
||||||
|
|
||||||
/* Check again from the current cursor position,
|
// Check again from the current cursor position,
|
||||||
* since the next match might actually be only one char wide */
|
// since the next match might actually be only one char wide
|
||||||
one_char = is_one_char(spats[last_idx].pat, false);
|
one_char = is_one_char(spats[last_idx].pat, false, &pos);
|
||||||
|
if (one_char < 0) {
|
||||||
|
// search failed, abort
|
||||||
|
return FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
/* move to match, except for zero-width matches, in which case, we are
|
/* move to match, except for zero-width matches, in which case, we are
|
||||||
* already on the next match */
|
* already on the next match */
|
||||||
@@ -4056,9 +4060,9 @@ current_search(
|
|||||||
|
|
||||||
/// Check if the pattern is one character long or zero-width.
|
/// Check if the pattern is one character long or zero-width.
|
||||||
/// If move is true, check from the beginning of the buffer,
|
/// If move is true, check from the beginning of the buffer,
|
||||||
/// else from the current cursor position.
|
/// else from position "cur".
|
||||||
/// Returns TRUE, FALSE or -1 for failure.
|
/// Returns TRUE, FALSE or -1 for failure.
|
||||||
static int is_one_char(char_u *pattern, bool move)
|
static int is_one_char(char_u *pattern, bool move, pos_T *cur)
|
||||||
{
|
{
|
||||||
regmmatch_T regmatch;
|
regmmatch_T regmatch;
|
||||||
int nmatched = 0;
|
int nmatched = 0;
|
||||||
@@ -4081,8 +4085,8 @@ static int is_one_char(char_u *pattern, bool move)
|
|||||||
if (move) {
|
if (move) {
|
||||||
clearpos(&pos);
|
clearpos(&pos);
|
||||||
} else {
|
} else {
|
||||||
pos = curwin->w_cursor;
|
pos = *cur;
|
||||||
/* accept a match at the cursor position */
|
// accept a match at the cursor position
|
||||||
flag = SEARCH_START;
|
flag = SEARCH_START;
|
||||||
}
|
}
|
||||||
if (searchit(curwin, curbuf, &pos, FORWARD, pattern, 1,
|
if (searchit(curwin, curbuf, &pos, FORWARD, pattern, 1,
|
||||||
|
@@ -1,43 +1,50 @@
|
|||||||
" Test for gn command
|
" Test for gn command
|
||||||
|
|
||||||
func Test_gn_command()
|
func Test_gn_command()
|
||||||
noa new
|
set belloff=all
|
||||||
|
noautocmd new
|
||||||
" replace a single char by itsself quoted:
|
" replace a single char by itsself quoted:
|
||||||
call setline('.', 'abc x def x ghi x jkl')
|
call setline('.', 'abc x def x ghi x jkl')
|
||||||
let @/='x'
|
let @/='x'
|
||||||
exe "norm! cgn'x'\<esc>.."
|
exe "norm! cgn'x'\<esc>.."
|
||||||
call assert_equal("abc 'x' def 'x' ghi 'x' jkl", getline('.'))
|
call assert_equal("abc 'x' def 'x' ghi 'x' jkl", getline('.'))
|
||||||
sil! %d_
|
sil! %d_
|
||||||
|
|
||||||
" simple search match
|
" simple search match
|
||||||
call setline('.', 'foobar')
|
call setline('.', 'foobar')
|
||||||
let @/='foobar'
|
let @/='foobar'
|
||||||
exe "norm! gncsearchmatch"
|
exe "norm! gncsearchmatch"
|
||||||
call assert_equal('searchmatch', getline('.'))
|
call assert_equal('searchmatch', getline('.'))
|
||||||
sil! %d _
|
sil! %d _
|
||||||
|
|
||||||
" replace a multi-line match
|
" replace a multi-line match
|
||||||
call setline('.', ['', 'one', 'two'])
|
call setline('.', ['', 'one', 'two'])
|
||||||
let @/='one\_s*two\_s'
|
let @/='one\_s*two\_s'
|
||||||
exe "norm! gnceins\<CR>zwei"
|
exe "norm! gnceins\<CR>zwei"
|
||||||
call assert_equal(['','eins','zwei'], getline(1,'$'))
|
call assert_equal(['','eins','zwei'], getline(1,'$'))
|
||||||
sil! %d _
|
sil! %d _
|
||||||
|
|
||||||
" test count argument
|
" test count argument
|
||||||
call setline('.', ['', 'abcdx | abcdx | abcdx'])
|
call setline('.', ['', 'abcdx | abcdx | abcdx'])
|
||||||
let @/='[a]bcdx'
|
let @/='[a]bcdx'
|
||||||
exe "norm! 2gnd"
|
exe "norm! 2gnd"
|
||||||
call assert_equal(['','abcdx | | abcdx'], getline(1,'$'))
|
call assert_equal(['','abcdx | | abcdx'], getline(1,'$'))
|
||||||
sil! %d _
|
sil! %d _
|
||||||
|
|
||||||
" join lines
|
" join lines
|
||||||
call setline('.', ['join ', 'lines'])
|
call setline('.', ['join ', 'lines'])
|
||||||
let @/='$'
|
let @/='$'
|
||||||
exe "norm! 0gnd"
|
exe "norm! 0gnd"
|
||||||
call assert_equal(['join lines'], getline(1,'$'))
|
call assert_equal(['join lines'], getline(1,'$'))
|
||||||
sil! %d _
|
sil! %d _
|
||||||
|
|
||||||
" zero-width match
|
" zero-width match
|
||||||
call setline('.', ['', 'zero width pattern'])
|
call setline('.', ['', 'zero width pattern'])
|
||||||
let @/='\>\zs'
|
let @/='\>\zs'
|
||||||
exe "norm! 0gnd"
|
exe "norm! 0gnd"
|
||||||
call assert_equal(['', 'zerowidth pattern'], getline(1,'$'))
|
call assert_equal(['', 'zerowidth pattern'], getline(1,'$'))
|
||||||
sil! %d _
|
sil! %d _
|
||||||
|
|
||||||
" delete first and last chars
|
" delete first and last chars
|
||||||
call setline('.', ['delete first and last chars'])
|
call setline('.', ['delete first and last chars'])
|
||||||
let @/='^'
|
let @/='^'
|
||||||
@@ -46,23 +53,27 @@ func Test_gn_command()
|
|||||||
exe "norm! gnd"
|
exe "norm! gnd"
|
||||||
call assert_equal(['elete first and last char'], getline(1,'$'))
|
call assert_equal(['elete first and last char'], getline(1,'$'))
|
||||||
sil! %d _
|
sil! %d _
|
||||||
|
|
||||||
" using visual mode
|
" using visual mode
|
||||||
call setline('.', ['', 'uniquepattern uniquepattern'])
|
call setline('.', ['', 'uniquepattern uniquepattern'])
|
||||||
exe "norm! /[u]niquepattern/s\<cr>vlgnd"
|
exe "norm! /[u]niquepattern/s\<cr>vlgnd"
|
||||||
call assert_equal(['', ' uniquepattern'], getline(1,'$'))
|
call assert_equal(['', ' uniquepattern'], getline(1,'$'))
|
||||||
sil! %d _
|
sil! %d _
|
||||||
|
|
||||||
" backwards search
|
" backwards search
|
||||||
call setline('.', ['my very excellent mother just served us nachos'])
|
call setline('.', ['my very excellent mother just served us nachos'])
|
||||||
let @/='mother'
|
let @/='mother'
|
||||||
exe "norm! $cgNmongoose"
|
exe "norm! $cgNmongoose"
|
||||||
call assert_equal(['my very excellent mongoose just served us nachos'], getline(1,'$'))
|
call assert_equal(['my very excellent mongoose just served us nachos'], getline(1,'$'))
|
||||||
sil! %d _
|
sil! %d _
|
||||||
|
|
||||||
" search for single char
|
" search for single char
|
||||||
call setline('.', ['','for (i=0; i<=10; i++)'])
|
call setline('.', ['','for (i=0; i<=10; i++)'])
|
||||||
let @/='i'
|
let @/='i'
|
||||||
exe "norm! cgnj"
|
exe "norm! cgnj"
|
||||||
call assert_equal(['','for (j=0; i<=10; i++)'], getline(1,'$'))
|
call assert_equal(['','for (j=0; i<=10; i++)'], getline(1,'$'))
|
||||||
sil! %d _
|
sil! %d _
|
||||||
|
|
||||||
" search hex char
|
" search hex char
|
||||||
call setline('.', ['','Y'])
|
call setline('.', ['','Y'])
|
||||||
set noignorecase
|
set noignorecase
|
||||||
@@ -70,24 +81,38 @@ func Test_gn_command()
|
|||||||
exe "norm! gnd"
|
exe "norm! gnd"
|
||||||
call assert_equal(['',''], getline(1,'$'))
|
call assert_equal(['',''], getline(1,'$'))
|
||||||
sil! %d _
|
sil! %d _
|
||||||
|
|
||||||
" test repeating gdn
|
" test repeating gdn
|
||||||
call setline('.', ['', '1', 'Johnny', '2', 'Johnny', '3'])
|
call setline('.', ['', '1', 'Johnny', '2', 'Johnny', '3'])
|
||||||
let @/='Johnny'
|
let @/='Johnny'
|
||||||
exe "norm! dgn."
|
exe "norm! dgn."
|
||||||
call assert_equal(['','1', '', '2', '', '3'], getline(1,'$'))
|
call assert_equal(['','1', '', '2', '', '3'], getline(1,'$'))
|
||||||
sil! %d _
|
sil! %d _
|
||||||
|
|
||||||
" test repeating gUgn
|
" test repeating gUgn
|
||||||
call setline('.', ['', '1', 'Depp', '2', 'Depp', '3'])
|
call setline('.', ['', '1', 'Depp', '2', 'Depp', '3'])
|
||||||
let @/='Depp'
|
let @/='Depp'
|
||||||
exe "norm! gUgn."
|
exe "norm! gUgn."
|
||||||
call assert_equal(['', '1', 'DEPP', '2', 'DEPP', '3'], getline(1,'$'))
|
call assert_equal(['', '1', 'DEPP', '2', 'DEPP', '3'], getline(1,'$'))
|
||||||
sil! %d _
|
sil! %d _
|
||||||
|
|
||||||
" test using look-ahead assertions
|
" test using look-ahead assertions
|
||||||
call setline('.', ['a:10', '', 'a:1', '', 'a:20'])
|
call setline('.', ['a:10', '', 'a:1', '', 'a:20'])
|
||||||
let @/='a:0\@!\zs\d\+'
|
let @/='a:0\@!\zs\d\+'
|
||||||
exe "norm! 2nygno\<esc>p"
|
exe "norm! 2nygno\<esc>p"
|
||||||
call assert_equal(['a:10', '', 'a:1', '1', '', 'a:20'], getline(1,'$'))
|
call assert_equal(['a:10', '', 'a:1', '1', '', 'a:20'], getline(1,'$'))
|
||||||
sil! %d _
|
sil! %d _
|
||||||
|
|
||||||
|
" test using nowrapscan
|
||||||
|
set nowrapscan
|
||||||
|
call setline(1, 'foo bar baz')
|
||||||
|
exe "norm! /bar/e\<cr>"
|
||||||
|
exe "norm! gnd"
|
||||||
|
call assert_equal(['foo baz'], getline(1,'$'))
|
||||||
|
sil! %d_
|
||||||
|
|
||||||
|
set wrapscan&vim
|
||||||
|
set belloff&vim
|
||||||
endfu
|
endfu
|
||||||
|
|
||||||
" vim: shiftwidth=2 sts=2 expandtab
|
" vim: shiftwidth=2 sts=2 expandtab
|
||||||
|
Reference in New Issue
Block a user