diff options
author | Bram Moolenaar <Bram@vim.org> | 2018-05-22 17:50:42 +0200 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2018-05-22 17:50:42 +0200 |
commit | bdb657924d73c98b0ab28411749571e893b699a9 (patch) | |
tree | c22c135229dcb6f04685cabd0db15505e68d2497 /src/search.c | |
parent | 62fe66f251263715968442e237742d9d3dfd5fa1 (diff) | |
download | vim-git-bdb657924d73c98b0ab28411749571e893b699a9.tar.gz |
patch 8.1.0018: using "gn" may select wrong text when wrappingv8.1.0018
Problem: Using "gn" may select wrong text when wrapping.
Solution: Avoid wrapping when searching forward. (Christian Brabandt)
Diffstat (limited to 'src/search.c')
-rw-r--r-- | src/search.c | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/src/search.c b/src/search.c index 726013e62..57434ec0b 100644 --- a/src/search.c +++ b/src/search.c @@ -4665,6 +4665,7 @@ current_search( { pos_T start_pos; /* position before the pattern */ pos_T orig_pos; /* position of the cursor at beginning */ + pos_T first_match; /* position of first match */ pos_T pos; /* position after the pattern */ int i; int dir; @@ -4758,6 +4759,8 @@ current_search( ml_get(curwin->w_buffer->b_ml.ml_line_count)); } } + if (i == 0) + first_match = pos; p_ws = old_p_ws; } @@ -4774,9 +4777,25 @@ 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, direction, + { + p_ws = FALSE; + for (i = 0; i < 2; i++) + { + result = searchit(curwin, curbuf, &pos, direction, spats[last_idx].pat, 0L, flags | SEARCH_KEEP, RE_SEARCH, 0, NULL, NULL); + /* Search successfull, break out from the loop */ + if (result) + break; + /* search failed, try again from the last search position match */ + pos = first_match; + } + } + + p_ws = old_p_ws; + /* not found */ + if (!result) + return FAIL; if (!VIsual_active) VIsual = start_pos; |