Bram, attached patch fixes this bug. On Do, 21 Sep 2017, fcpg wrote:
> - Create new file: > foo > bar > foo > baz > > - search for 'foo': > gg* > > - move to last line: > G > > - type gN with wrapscan; it works correctly (foo on 3rd line is visually > selected) > set wrapscan > gN > > - unset wrapscan, move back to last line and type gN; cursor doesn't move, > nothing is selected; > set nowrapscan > G > gN > > Best, Christian -- Das Leben ist voller Farbe, aber manchmal wird es einem zu bunt. -- -- You received this message from the "vim_dev" maillist. Do not top-post! Type your reply below the text you are replying to. For more information, visit http://www.vim.org/maillist.php --- You received this message because you are subscribed to the Google Groups "vim_dev" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
From 931a151891e89715bdd4497531f395fb8dd209f3 Mon Sep 17 00:00:00 2001 From: Christian Brabandt <[email protected]> Date: Mon, 25 Sep 2017 14:12:42 +0200 Subject: [PATCH] Fix gn bug When testing whether the search result is zero/one-char width, we did not consider the direction of the search, so is_one_char() would return -1 since it starts looking from the end position for a match in forward direction. So make it search into the correct direction. fix #2137 --- src/search.c | 19 ++++++++++--------- src/testdir/test_gn.vim | 9 +++++++++ 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/src/search.c b/src/search.c index 15d9b81f7..6fbd52854 100644 --- a/src/search.c +++ b/src/search.c @@ -4611,7 +4611,7 @@ current_quote( #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 dir); /* * Find next search match under cursor, cursor at end. @@ -4632,6 +4632,7 @@ current_search( int flags = 0; pos_T save_VIsual = VIsual; int one_char; + int direction = forward ? FORWARD : BACKWARD; /* wrapping should not occur */ p_ws = FALSE; @@ -4658,8 +4659,8 @@ current_search( else orig_pos = pos = curwin->w_cursor; - /* Is the pattern is zero-width? */ - one_char = is_one_char(spats[last_idx].pat, TRUE, &curwin->w_cursor); + /* 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, FORWARD); if (one_char == -1) { p_ws = old_p_ws; @@ -4718,11 +4719,11 @@ current_search( } start_pos = pos; - flags = forward ? SEARCH_END : 0; + flags = forward ? SEARCH_END : SEARCH_START; /* Check again from the current cursor position, * 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) /* search failed, abort */ return FAIL; @@ -4730,7 +4731,7 @@ current_search( /* move to match, except for zero-width matches, in which case, we are * already on the next match */ 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, NULL, NULL); @@ -4782,7 +4783,7 @@ current_search( * Returns TRUE, FALSE or -1 for failure. */ 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 dir) { regmmatch_T regmatch; int nmatched = 0; @@ -4812,7 +4813,7 @@ is_one_char(char_u *pattern, int move, pos_T *cur) flag = SEARCH_START; } - if (searchit(curwin, curbuf, &pos, FORWARD, pattern, 1, + if (searchit(curwin, curbuf, &pos, dir, pattern, 1, SEARCH_KEEP + flag, RE_SEARCH, 0, NULL, NULL) != FAIL) { /* Zero-width pattern should match somewhere, then we can check if @@ -4825,7 +4826,7 @@ is_one_char(char_u *pattern, int move, pos_T *cur) pos.lnum, regmatch.startpos[0].col, NULL, NULL); if (!nmatched) break; - } while (regmatch.startpos[0].col < pos.col); + } while ( dir == FORWARD ? regmatch.startpos[0].col < pos.col : regmatch.startpos[0].col > pos.col); if (!called_emsg) { diff --git a/src/testdir/test_gn.vim b/src/testdir/test_gn.vim index b2a2937d8..f56e707da 100644 --- a/src/testdir/test_gn.vim +++ b/src/testdir/test_gn.vim @@ -111,6 +111,15 @@ func Test_gn_command() call assert_equal(['foo baz'], getline(1,'$')) 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 belloff&vim endfu -- 2.14.1
