summaryrefslogtreecommitdiff
path: root/src/search.c
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2017-06-05 19:56:04 +0200
committerBram Moolenaar <Bram@vim.org>2017-06-05 19:56:04 +0200
commitadd8dce38de65a0c64e8f54d6bdcadb45a8de2cf (patch)
tree3052a6d3393a6ce4e93e76c63094c5e0da063854 /src/search.c
parente21d69eec1870a3f4732653aa8ee25d5da10128c (diff)
downloadvim-git-add8dce38de65a0c64e8f54d6bdcadb45a8de2cf.tar.gz
patch 8.0.0627: "gn" selects only one character with 'nowrapscan'v8.0.0627
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 #1683)
Diffstat (limited to 'src/search.c')
-rw-r--r--src/search.c17
1 files changed, 10 insertions, 7 deletions
diff --git a/src/search.c b/src/search.c
index c1197160a..947007341 100644
--- a/src/search.c
+++ b/src/search.c
@@ -4599,7 +4599,7 @@ current_quote(
#endif /* FEAT_TEXTOBJ */
-static int is_one_char(char_u *pattern, int move);
+static int is_one_char(char_u *pattern, int move, pos_T *cur);
/*
* Find next search match under cursor, cursor at end.
@@ -4647,7 +4647,7 @@ current_search(
orig_pos = pos = curwin->w_cursor;
/* Is the pattern is zero-width? */
- one_char = is_one_char(spats[last_idx].pat, TRUE);
+ one_char = is_one_char(spats[last_idx].pat, TRUE, &curwin->w_cursor);
if (one_char == -1)
{
p_ws = old_p_ws;
@@ -4710,7 +4710,10 @@ current_search(
/* 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);
+ 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 */
@@ -4761,12 +4764,12 @@ 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.
+ * If move is TRUE, check from the beginning of the buffer, else from position
+ * "cur".
* Returns TRUE, FALSE or -1 for failure.
*/
static int
-is_one_char(char_u *pattern, int move)
+is_one_char(char_u *pattern, int move, pos_T *cur)
{
regmmatch_T regmatch;
int nmatched = 0;
@@ -4791,7 +4794,7 @@ is_one_char(char_u *pattern, int move)
}
else
{
- pos = curwin->w_cursor;
+ pos = *cur;
/* accept a match at the cursor position */
flag = SEARCH_START;
}