Mercurial > vim
comparison 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 |
comparison
equal
deleted
inserted
replaced
11487:b3d343436f92 | 11488:9473793c7bb5 |
---|---|
4597 return OK; | 4597 return OK; |
4598 } | 4598 } |
4599 | 4599 |
4600 #endif /* FEAT_TEXTOBJ */ | 4600 #endif /* FEAT_TEXTOBJ */ |
4601 | 4601 |
4602 static int is_one_char(char_u *pattern, int move); | 4602 static int is_one_char(char_u *pattern, int move, pos_T *cur); |
4603 | 4603 |
4604 /* | 4604 /* |
4605 * Find next search match under cursor, cursor at end. | 4605 * Find next search match under cursor, cursor at end. |
4606 * Used while an operator is pending, and in Visual mode. | 4606 * Used while an operator is pending, and in Visual mode. |
4607 */ | 4607 */ |
4645 } | 4645 } |
4646 else | 4646 else |
4647 orig_pos = pos = curwin->w_cursor; | 4647 orig_pos = pos = curwin->w_cursor; |
4648 | 4648 |
4649 /* Is the pattern is zero-width? */ | 4649 /* Is the pattern is zero-width? */ |
4650 one_char = is_one_char(spats[last_idx].pat, TRUE); | 4650 one_char = is_one_char(spats[last_idx].pat, TRUE, &curwin->w_cursor); |
4651 if (one_char == -1) | 4651 if (one_char == -1) |
4652 { | 4652 { |
4653 p_ws = old_p_ws; | 4653 p_ws = old_p_ws; |
4654 return FAIL; /* pattern not found */ | 4654 return FAIL; /* pattern not found */ |
4655 } | 4655 } |
4708 start_pos = pos; | 4708 start_pos = pos; |
4709 flags = forward ? SEARCH_END : 0; | 4709 flags = forward ? SEARCH_END : 0; |
4710 | 4710 |
4711 /* Check again from the current cursor position, | 4711 /* Check again from the current cursor position, |
4712 * since the next match might actually by only one char wide */ | 4712 * since the next match might actually by only one char wide */ |
4713 one_char = is_one_char(spats[last_idx].pat, FALSE); | 4713 one_char = is_one_char(spats[last_idx].pat, FALSE, &pos); |
4714 if (one_char < 0) | |
4715 /* search failed, abort */ | |
4716 return FAIL; | |
4714 | 4717 |
4715 /* move to match, except for zero-width matches, in which case, we are | 4718 /* move to match, except for zero-width matches, in which case, we are |
4716 * already on the next match */ | 4719 * already on the next match */ |
4717 if (!one_char) | 4720 if (!one_char) |
4718 result = searchit(curwin, curbuf, &pos, (forward ? FORWARD : BACKWARD), | 4721 result = searchit(curwin, curbuf, &pos, (forward ? FORWARD : BACKWARD), |
4759 return OK; | 4762 return OK; |
4760 } | 4763 } |
4761 | 4764 |
4762 /* | 4765 /* |
4763 * Check if the pattern is one character long or zero-width. | 4766 * Check if the pattern is one character long or zero-width. |
4764 * If move is TRUE, check from the beginning of the buffer, else from the | 4767 * If move is TRUE, check from the beginning of the buffer, else from position |
4765 * current cursor position. | 4768 * "cur". |
4766 * Returns TRUE, FALSE or -1 for failure. | 4769 * Returns TRUE, FALSE or -1 for failure. |
4767 */ | 4770 */ |
4768 static int | 4771 static int |
4769 is_one_char(char_u *pattern, int move) | 4772 is_one_char(char_u *pattern, int move, pos_T *cur) |
4770 { | 4773 { |
4771 regmmatch_T regmatch; | 4774 regmmatch_T regmatch; |
4772 int nmatched = 0; | 4775 int nmatched = 0; |
4773 int result = -1; | 4776 int result = -1; |
4774 pos_T pos; | 4777 pos_T pos; |
4789 { | 4792 { |
4790 CLEAR_POS(&pos); | 4793 CLEAR_POS(&pos); |
4791 } | 4794 } |
4792 else | 4795 else |
4793 { | 4796 { |
4794 pos = curwin->w_cursor; | 4797 pos = *cur; |
4795 /* accept a match at the cursor position */ | 4798 /* accept a match at the cursor position */ |
4796 flag = SEARCH_START; | 4799 flag = SEARCH_START; |
4797 } | 4800 } |
4798 | 4801 |
4799 if (searchit(curwin, curbuf, &pos, FORWARD, pattern, 1, | 4802 if (searchit(curwin, curbuf, &pos, FORWARD, pattern, 1, |