mirror of
https://github.com/vim/vim.git
synced 2025-09-23 03:43:49 -04:00
patch 8.1.0018: using "gn" may select wrong text when wrapping
Problem: Using "gn" may select wrong text when wrapping. Solution: Avoid wrapping when searching forward. (Christian Brabandt)
This commit is contained in:
19
src/search.c
19
src/search.c
@@ -4665,6 +4665,7 @@ current_search(
|
|||||||
{
|
{
|
||||||
pos_T start_pos; /* position before the pattern */
|
pos_T start_pos; /* position before the pattern */
|
||||||
pos_T orig_pos; /* position of the cursor at beginning */
|
pos_T orig_pos; /* position of the cursor at beginning */
|
||||||
|
pos_T first_match; /* position of first match */
|
||||||
pos_T pos; /* position after the pattern */
|
pos_T pos; /* position after the pattern */
|
||||||
int i;
|
int i;
|
||||||
int dir;
|
int dir;
|
||||||
@@ -4758,6 +4759,8 @@ current_search(
|
|||||||
ml_get(curwin->w_buffer->b_ml.ml_line_count));
|
ml_get(curwin->w_buffer->b_ml.ml_line_count));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (i == 0)
|
||||||
|
first_match = pos;
|
||||||
p_ws = old_p_ws;
|
p_ws = old_p_ws;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -4774,9 +4777,25 @@ current_search(
|
|||||||
/* 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 */
|
||||||
if (!one_char)
|
if (!one_char)
|
||||||
|
{
|
||||||
|
p_ws = FALSE;
|
||||||
|
for (i = 0; i < 2; i++)
|
||||||
|
{
|
||||||
result = searchit(curwin, curbuf, &pos, direction,
|
result = searchit(curwin, curbuf, &pos, direction,
|
||||||
spats[last_idx].pat, 0L, flags | SEARCH_KEEP, RE_SEARCH, 0,
|
spats[last_idx].pat, 0L, flags | SEARCH_KEEP, RE_SEARCH, 0,
|
||||||
NULL, NULL);
|
NULL, NULL);
|
||||||
|
/* Search successfull, break out from the loop */
|
||||||
|
if (result)
|
||||||
|
break;
|
||||||
|
/* search failed, try again from the last search position match */
|
||||||
|
pos = first_match;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
p_ws = old_p_ws;
|
||||||
|
/* not found */
|
||||||
|
if (!result)
|
||||||
|
return FAIL;
|
||||||
|
|
||||||
if (!VIsual_active)
|
if (!VIsual_active)
|
||||||
VIsual = start_pos;
|
VIsual = start_pos;
|
||||||
|
@@ -119,6 +119,15 @@ func Test_gn_command()
|
|||||||
call assert_equal(['foo', 'bar', '', 'baz'], getline(1,'$'))
|
call assert_equal(['foo', 'bar', '', 'baz'], getline(1,'$'))
|
||||||
sil! %d_
|
sil! %d_
|
||||||
|
|
||||||
|
" search using the \zs atom
|
||||||
|
call setline(1, [' nnoremap', '' , 'nnoremap'])
|
||||||
|
set wrapscan&vim
|
||||||
|
let @/ = '\_s\zsnnoremap'
|
||||||
|
$
|
||||||
|
norm! cgnmatch
|
||||||
|
call assert_equal([' nnoremap', '', 'match'], getline(1,'$'))
|
||||||
|
sil! %d_
|
||||||
|
|
||||||
set wrapscan&vim
|
set wrapscan&vim
|
||||||
endfu
|
endfu
|
||||||
|
|
||||||
|
@@ -761,6 +761,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
18,
|
||||||
/**/
|
/**/
|
||||||
17,
|
17,
|
||||||
/**/
|
/**/
|
||||||
|
Reference in New Issue
Block a user