comparison src/search.c @ 18500:c0445cb7cfe0 v8.1.2244

patch 8.1.2244: 'wrapscan' is not used for "gn" Commit: https://github.com/vim/vim/commit/82cf7f6df751505da285815a791463a049587849 Author: Bram Moolenaar <Bram@vim.org> Date: Sat Nov 2 23:22:47 2019 +0100 patch 8.1.2244: 'wrapscan' is not used for "gn" Problem: 'wrapscan' is not used for "gn". Solution: Only reset 'wrapscan' for the first search round. (closes https://github.com/vim/vim/issues/5164)
author Bram Moolenaar <Bram@vim.org>
date Sat, 02 Nov 2019 23:30:04 +0100
parents 35e0ab1f2975
children bbea1f108187
comparison
equal deleted inserted replaced
18499:b27ed4764264 18500:c0445cb7cfe0
4763 char_u old_p_ws = p_ws; 4763 char_u old_p_ws = p_ws;
4764 int flags = 0; 4764 int flags = 0;
4765 pos_T save_VIsual = VIsual; 4765 pos_T save_VIsual = VIsual;
4766 int zero_width; 4766 int zero_width;
4767 4767
4768 /* wrapping should not occur */
4769 p_ws = FALSE;
4770
4771 /* Correct cursor when 'selection' is exclusive */ 4768 /* Correct cursor when 'selection' is exclusive */
4772 if (VIsual_active && *p_sel == 'e' && LT_POS(VIsual, curwin->w_cursor)) 4769 if (VIsual_active && *p_sel == 'e' && LT_POS(VIsual, curwin->w_cursor))
4773 dec_cursor(); 4770 dec_cursor();
4774 4771
4775 orig_pos = pos = curwin->w_cursor; 4772 orig_pos = pos = curwin->w_cursor;
4784 /* Is the pattern is zero-width?, this time, don't care about the direction 4781 /* Is the pattern is zero-width?, this time, don't care about the direction
4785 */ 4782 */
4786 zero_width = is_zero_width(spats[last_idx].pat, TRUE, &curwin->w_cursor, 4783 zero_width = is_zero_width(spats[last_idx].pat, TRUE, &curwin->w_cursor,
4787 FORWARD); 4784 FORWARD);
4788 if (zero_width == -1) 4785 if (zero_width == -1)
4789 {
4790 p_ws = old_p_ws;
4791 return FAIL; /* pattern not found */ 4786 return FAIL; /* pattern not found */
4792 }
4793 4787
4794 /* 4788 /*
4795 * The trick is to first search backwards and then search forward again, 4789 * The trick is to first search backwards and then search forward again,
4796 * so that a match at the current cursor position will be correctly 4790 * so that a match at the current cursor position will be correctly
4797 * captured. 4791 * captured.
4806 flags = 0; 4800 flags = 0;
4807 if (!dir && !zero_width) 4801 if (!dir && !zero_width)
4808 flags = SEARCH_END; 4802 flags = SEARCH_END;
4809 end_pos = pos; 4803 end_pos = pos;
4810 4804
4805 // wrapping should not occur in the first round
4806 if (i == 0)
4807 p_ws = FALSE;
4808
4811 result = searchit(curwin, curbuf, &pos, &end_pos, 4809 result = searchit(curwin, curbuf, &pos, &end_pos,
4812 (dir ? FORWARD : BACKWARD), 4810 (dir ? FORWARD : BACKWARD),
4813 spats[last_idx].pat, (long) (i ? count : 1), 4811 spats[last_idx].pat, (long) (i ? count : 1),
4814 SEARCH_KEEP | flags, RE_SEARCH, NULL); 4812 SEARCH_KEEP | flags, RE_SEARCH, NULL);
4813
4814 p_ws = old_p_ws;
4815 4815
4816 /* First search may fail, but then start searching from the 4816 /* First search may fail, but then start searching from the
4817 * beginning of the file (cursor might be on the search match) 4817 * beginning of the file (cursor might be on the search match)
4818 * except when Visual mode is active, so that extending the visual 4818 * except when Visual mode is active, so that extending the visual
4819 * selection works. */ 4819 * selection works. */
4820 if (i == 1 && !result) /* not found, abort */ 4820 if (i == 1 && !result) /* not found, abort */
4821 { 4821 {
4822 curwin->w_cursor = orig_pos; 4822 curwin->w_cursor = orig_pos;
4823 if (VIsual_active) 4823 if (VIsual_active)
4824 VIsual = save_VIsual; 4824 VIsual = save_VIsual;
4825 p_ws = old_p_ws;
4826 return FAIL; 4825 return FAIL;
4827 } 4826 }
4828 else if (i == 0 && !result) 4827 else if (i == 0 && !result)
4829 { 4828 {
4830 if (forward) 4829 if (forward)
4842 } 4841 }
4843 } 4842 }
4844 } 4843 }
4845 4844
4846 start_pos = pos; 4845 start_pos = pos;
4847 p_ws = old_p_ws;
4848 4846
4849 if (!VIsual_active) 4847 if (!VIsual_active)
4850 VIsual = start_pos; 4848 VIsual = start_pos;
4851 4849
4852 // put cursor on last character of match 4850 // put cursor on last character of match