0
0
mirror of https://github.com/vim/vim.git synced 2025-07-26 11:04:33 -04:00

patch 8.0.1148: gN doesn't work on last match with 'wrapscan' off

Problem:    "gN" doesn't work on last match with 'wrapscan' off. (fcpg)
Solution:   Adjust for searching backward. (Christian Brabandt)
This commit is contained in:
Bram Moolenaar 2017-09-26 12:28:45 +02:00
parent 7c456a4511
commit 22ab547dc2
3 changed files with 25 additions and 9 deletions

View File

@ -4611,7 +4611,7 @@ current_quote(
#endif /* FEAT_TEXTOBJ */ #endif /* FEAT_TEXTOBJ */
static int is_one_char(char_u *pattern, int move, pos_T *cur); static int is_one_char(char_u *pattern, int move, pos_T *cur, int direction);
/* /*
* Find next search match under cursor, cursor at end. * Find next search match under cursor, cursor at end.
@ -4632,6 +4632,7 @@ current_search(
int flags = 0; int flags = 0;
pos_T save_VIsual = VIsual; pos_T save_VIsual = VIsual;
int one_char; int one_char;
int direction = forward ? FORWARD : BACKWARD;
/* wrapping should not occur */ /* wrapping should not occur */
p_ws = FALSE; p_ws = FALSE;
@ -4658,8 +4659,10 @@ current_search(
else else
orig_pos = pos = curwin->w_cursor; orig_pos = pos = curwin->w_cursor;
/* Is the pattern is zero-width? */ /* Is the pattern is zero-width?, this time, don't care about the direction
one_char = is_one_char(spats[last_idx].pat, TRUE, &curwin->w_cursor); */
one_char = is_one_char(spats[last_idx].pat, TRUE, &curwin->w_cursor,
FORWARD);
if (one_char == -1) if (one_char == -1)
{ {
p_ws = old_p_ws; p_ws = old_p_ws;
@ -4718,11 +4721,11 @@ current_search(
} }
start_pos = pos; start_pos = pos;
flags = forward ? SEARCH_END : 0; flags = forward ? SEARCH_END : SEARCH_START;
/* Check again from the current cursor position, /* Check again from the current cursor position,
* since the next match might actually by only one char wide */ * since the next match might actually by only one char wide */
one_char = is_one_char(spats[last_idx].pat, FALSE, &pos); one_char = is_one_char(spats[last_idx].pat, FALSE, &pos, direction);
if (one_char < 0) if (one_char < 0)
/* search failed, abort */ /* search failed, abort */
return FAIL; return FAIL;
@ -4730,7 +4733,7 @@ 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)
result = searchit(curwin, curbuf, &pos, (forward ? FORWARD : BACKWARD), 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);
@ -4779,10 +4782,11 @@ 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, else from position * If move is TRUE, check from the beginning of the buffer, else from position
* "cur". * "cur".
* "direction" is FORWARD or BACKWARD.
* Returns TRUE, FALSE or -1 for failure. * Returns TRUE, FALSE or -1 for failure.
*/ */
static int static int
is_one_char(char_u *pattern, int move, pos_T *cur) is_one_char(char_u *pattern, int move, pos_T *cur, int direction)
{ {
regmmatch_T regmatch; regmmatch_T regmatch;
int nmatched = 0; int nmatched = 0;
@ -4812,7 +4816,7 @@ is_one_char(char_u *pattern, int move, pos_T *cur)
flag = SEARCH_START; flag = SEARCH_START;
} }
if (searchit(curwin, curbuf, &pos, FORWARD, pattern, 1, if (searchit(curwin, curbuf, &pos, direction, pattern, 1,
SEARCH_KEEP + flag, RE_SEARCH, 0, NULL, NULL) != FAIL) SEARCH_KEEP + flag, RE_SEARCH, 0, NULL, NULL) != FAIL)
{ {
/* Zero-width pattern should match somewhere, then we can check if /* Zero-width pattern should match somewhere, then we can check if
@ -4825,7 +4829,8 @@ is_one_char(char_u *pattern, int move, pos_T *cur)
pos.lnum, regmatch.startpos[0].col, NULL, NULL); pos.lnum, regmatch.startpos[0].col, NULL, NULL);
if (!nmatched) if (!nmatched)
break; break;
} while (regmatch.startpos[0].col < pos.col); } while (direction == FORWARD ? regmatch.startpos[0].col < pos.col
: regmatch.startpos[0].col > pos.col);
if (!called_emsg) if (!called_emsg)
{ {

View File

@ -111,6 +111,15 @@ func Test_gn_command()
call assert_equal(['foo baz'], getline(1,'$')) call assert_equal(['foo baz'], getline(1,'$'))
sil! %d_ sil! %d_
" search upwards with nowrapscan set
call setline('.', ['foo', 'bar', 'foo', 'baz'])
set nowrapscan
let @/='foo'
$
norm! dgN
call assert_equal(['foo', 'bar', '', 'baz'], getline(1,'$'))
sil! %d_
set wrapscan&vim set wrapscan&vim
set belloff&vim set belloff&vim
endfu endfu

View File

@ -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 */
/**/
1148,
/**/ /**/
1147, 1147,
/**/ /**/