diff src/search.c @ 11488:9473793c7bb5 v8.0.0627

patch 8.0.0627: "gn" selects only one character with 'nowrapscan' commit https://github.com/vim/vim/commit/add8dce38de65a0c64e8f54d6bdcadb45a8de2cf Author: Bram Moolenaar <Bram@vim.org> Date: Mon Jun 5 19:56:04 2017 +0200 patch 8.0.0627: "gn" selects only one character with 'nowrapscan' 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)
author Christian Brabandt <cb@256bit.org>
date Mon, 05 Jun 2017 20:00:04 +0200
parents 29a781fd3f27
children 578df034735d
line wrap: on
line diff
--- 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;
     }