forked from aniani/vim
patch 8.2.1837: using "gn" after "gN" does not work
Problem: Using "gn" after "gN" does not work. Solution: Extend the other end of the Visual area. (closes #7109)
This commit is contained in:
23
src/search.c
23
src/search.c
@@ -2961,11 +2961,17 @@ current_search(
|
|||||||
int flags = 0;
|
int flags = 0;
|
||||||
pos_T save_VIsual = VIsual;
|
pos_T save_VIsual = VIsual;
|
||||||
int zero_width;
|
int zero_width;
|
||||||
|
int skip_first_backward;
|
||||||
|
|
||||||
// Correct cursor when 'selection' is exclusive
|
// Correct cursor when 'selection' is exclusive
|
||||||
if (VIsual_active && *p_sel == 'e' && LT_POS(VIsual, curwin->w_cursor))
|
if (VIsual_active && *p_sel == 'e' && LT_POS(VIsual, curwin->w_cursor))
|
||||||
dec_cursor();
|
dec_cursor();
|
||||||
|
|
||||||
|
// When searching forward and the cursor is at the start of the Visual
|
||||||
|
// area, skip the first search backward, otherwise it doesn't move.
|
||||||
|
skip_first_backward = forward && VIsual_active
|
||||||
|
&& LT_POS(curwin->w_cursor, VIsual);
|
||||||
|
|
||||||
orig_pos = pos = curwin->w_cursor;
|
orig_pos = pos = curwin->w_cursor;
|
||||||
if (VIsual_active)
|
if (VIsual_active)
|
||||||
{
|
{
|
||||||
@@ -2984,12 +2990,16 @@ current_search(
|
|||||||
/*
|
/*
|
||||||
* The trick is to first search backwards and then search forward again,
|
* The trick is to first search backwards and then search forward again,
|
||||||
* so that a match at the current cursor position will be correctly
|
* so that a match at the current cursor position will be correctly
|
||||||
* captured.
|
* captured. When "forward" is false do it the other way around.
|
||||||
*/
|
*/
|
||||||
for (i = 0; i < 2; i++)
|
for (i = 0; i < 2; i++)
|
||||||
{
|
{
|
||||||
if (forward)
|
if (forward)
|
||||||
|
{
|
||||||
|
if (i == 0 && skip_first_backward)
|
||||||
|
continue;
|
||||||
dir = i;
|
dir = i;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
dir = !i;
|
dir = !i;
|
||||||
|
|
||||||
@@ -3043,10 +3053,17 @@ current_search(
|
|||||||
if (!VIsual_active)
|
if (!VIsual_active)
|
||||||
VIsual = start_pos;
|
VIsual = start_pos;
|
||||||
|
|
||||||
// put cursor on last character of match
|
// put the cursor after the match
|
||||||
curwin->w_cursor = end_pos;
|
curwin->w_cursor = end_pos;
|
||||||
if (LT_POS(VIsual, end_pos) && forward)
|
if (LT_POS(VIsual, end_pos) && forward)
|
||||||
dec_cursor();
|
{
|
||||||
|
if (skip_first_backward)
|
||||||
|
// put the cursor on the start of the match
|
||||||
|
curwin->w_cursor = pos;
|
||||||
|
else
|
||||||
|
// put the cursor on last character of match
|
||||||
|
dec_cursor();
|
||||||
|
}
|
||||||
else if (VIsual_active && LT_POS(curwin->w_cursor, VIsual) && forward)
|
else if (VIsual_active && LT_POS(curwin->w_cursor, VIsual) && forward)
|
||||||
curwin->w_cursor = pos; // put the cursor on the start of the match
|
curwin->w_cursor = pos; // put the cursor on the start of the match
|
||||||
VIsual_active = TRUE;
|
VIsual_active = TRUE;
|
||||||
|
@@ -183,6 +183,22 @@ func Test_gN_repeat()
|
|||||||
bwipe!
|
bwipe!
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
|
func Test_gN_then_gn()
|
||||||
|
new
|
||||||
|
|
||||||
|
call setline(1, 'this list is a list with a list of a last.')
|
||||||
|
/l.st
|
||||||
|
normal $gNgNgnx
|
||||||
|
call assert_equal('last', @")
|
||||||
|
|
||||||
|
call setline(1, 'this list is a list with a lust of a last.')
|
||||||
|
/l.st
|
||||||
|
normal $gNgNgNgnx
|
||||||
|
call assert_equal('lust of a last', @")
|
||||||
|
|
||||||
|
bwipe!
|
||||||
|
endfunc
|
||||||
|
|
||||||
func Test_gn_multi_line()
|
func Test_gn_multi_line()
|
||||||
new
|
new
|
||||||
call setline(1, [
|
call setline(1, [
|
||||||
|
@@ -750,6 +750,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
1837,
|
||||||
/**/
|
/**/
|
||||||
1836,
|
1836,
|
||||||
/**/
|
/**/
|
||||||
|
Reference in New Issue
Block a user