vim-patch:8.1.2244: 'wrapscan' is not used for "gn"

Problem:    'wrapscan' is not used for "gn".
Solution:   Only reset 'wrapscan' for the first search round. (closes vim/vim#5164)
82cf7f6df7
This commit is contained in:
Jan Edmund Lazo 2019-11-06 00:21:26 -05:00
parent 5689008060
commit b8a56e0986
No known key found for this signature in database
GPG Key ID: 64915E6E9F735B15
2 changed files with 10 additions and 9 deletions

View File

@ -4037,9 +4037,6 @@ current_search(
bool old_p_ws = p_ws; bool old_p_ws = p_ws;
pos_T save_VIsual = VIsual; pos_T save_VIsual = VIsual;
/* wrapping should not occur */
p_ws = false;
/* Correct cursor when 'selection' is exclusive */ /* Correct cursor when 'selection' is exclusive */
if (VIsual_active && *p_sel == 'e' && lt(VIsual, curwin->w_cursor)) if (VIsual_active && *p_sel == 'e' && lt(VIsual, curwin->w_cursor))
dec_cursor(); dec_cursor();
@ -4063,8 +4060,7 @@ current_search(
int zero_width = is_zero_width(spats[last_idx].pat, true, &curwin->w_cursor, int zero_width = is_zero_width(spats[last_idx].pat, true, &curwin->w_cursor,
FORWARD); FORWARD);
if (zero_width == -1) { if (zero_width == -1) {
p_ws = old_p_ws; return FAIL; // pattern not found
return FAIL; /* pattern not found */
} }
/* /*
@ -4081,11 +4077,18 @@ current_search(
} }
end_pos = pos; end_pos = pos;
// wrapping should not occur in the first round
if (i == 0) {
p_ws = false;
}
result = searchit(curwin, curbuf, &pos, &end_pos, result = searchit(curwin, curbuf, &pos, &end_pos,
(dir ? FORWARD : BACKWARD), (dir ? FORWARD : BACKWARD),
spats[last_idx].pat, i ? count : 1, spats[last_idx].pat, i ? count : 1,
SEARCH_KEEP | flags, RE_SEARCH, NULL); SEARCH_KEEP | flags, RE_SEARCH, NULL);
p_ws = old_p_ws;
// First search may fail, but then start searching from the // First search may fail, but then start searching from the
// beginning of the file (cursor might be on the search match) // beginning of the file (cursor might be on the search match)
// except when Visual mode is active, so that extending the visual // except when Visual mode is active, so that extending the visual
@ -4094,7 +4097,6 @@ current_search(
curwin->w_cursor = orig_pos; curwin->w_cursor = orig_pos;
if (VIsual_active) if (VIsual_active)
VIsual = save_VIsual; VIsual = save_VIsual;
p_ws = old_p_ws;
return FAIL; return FAIL;
} else if (i == 0 && !result) { } else if (i == 0 && !result) {
if (forward) { // try again from start of buffer if (forward) { // try again from start of buffer
@ -4110,8 +4112,6 @@ current_search(
pos_T start_pos = pos; pos_T start_pos = pos;
p_ws = old_p_ws;
if (!VIsual_active) { if (!VIsual_active) {
VIsual = start_pos; VIsual = start_pos;
} }

View File

@ -136,8 +136,9 @@ func Test_gn_command()
call assert_equal(['ABCDEFGHi'], getline(1,'$')) call assert_equal(['ABCDEFGHi'], getline(1,'$'))
call setline('.', ['abcdefghi']) call setline('.', ['abcdefghi'])
let @/ = 'b' let @/ = 'b'
" this gn wraps around the end of the file
exe "norm! 0fhvhhgngU" exe "norm! 0fhvhhgngU"
call assert_equal(['abcdefghi'], getline(1,'$')) call assert_equal(['aBCDEFGHi'], getline(1,'$'))
sil! %d _ sil! %d _
call setline('.', ['abcdefghi']) call setline('.', ['abcdefghi'])
let @/ = 'f' let @/ = 'f'