diff options
author | Jan Edmund Lazo <jan.lazo@mail.utoronto.ca> | 2018-06-24 04:37:59 -0400 |
---|---|---|
committer | Justin M. Keyes <justinkz@gmail.com> | 2018-06-24 10:37:59 +0200 |
commit | 3d688cc25dab84b3b4647d6148ad905e6a5e5a64 (patch) | |
tree | 1e8892535cbb4c1e8e3f7bb3bbc3a6d41c34893a /src/nvim/search.c | |
parent | bf6048e81d63c26231209ea82d05fb8e948dc573 (diff) | |
download | rneovim-3d688cc25dab84b3b4647d6148ad905e6a5e5a64.tar.gz rneovim-3d688cc25dab84b3b4647d6148ad905e6a5e5a64.tar.bz2 rneovim-3d688cc25dab84b3b4647d6148ad905e6a5e5a64.zip |
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)
https://github.com/vim/vim/commit/add8dce38de65a0c64e8f54d6bdcadb45a8de2cf
Diffstat (limited to 'src/nvim/search.c')
-rw-r--r-- | src/nvim/search.c | 22 |
1 files changed, 13 insertions, 9 deletions
diff --git a/src/nvim/search.c b/src/nvim/search.c index 27f4389683..578d1fd35a 100644 --- a/src/nvim/search.c +++ b/src/nvim/search.c @@ -3966,8 +3966,8 @@ current_search( orig_pos = pos = curwin->w_cursor; } - /* Is the pattern is zero-width? */ - int one_char = is_one_char(spats[last_idx].pat, true); + // Is the pattern is zero-width? + int one_char = is_one_char(spats[last_idx].pat, true, &curwin->w_cursor); if (one_char == -1) { p_ws = old_p_ws; return FAIL; /* pattern not found */ @@ -4015,9 +4015,13 @@ current_search( int flags = forward ? SEARCH_END : 0; pos_T start_pos = pos; - /* Check again from the current cursor position, - * since the next match might actually be only one char wide */ - one_char = is_one_char(spats[last_idx].pat, false); + // Check again from the current cursor position, + // since the next match might actually be only one char wide + 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 * already on the next match */ @@ -4056,9 +4060,9 @@ current_search( /// Check if the pattern is one character long or zero-width. /// 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. -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; int nmatched = 0; @@ -4081,8 +4085,8 @@ static int is_one_char(char_u *pattern, bool move) if (move) { clearpos(&pos); } else { - pos = curwin->w_cursor; - /* accept a match at the cursor position */ + pos = *cur; + // accept a match at the cursor position flag = SEARCH_START; } if (searchit(curwin, curbuf, &pos, FORWARD, pattern, 1, |