Skip to content

Commit c5e2b04

Browse files
committed
patch 8.0.0622: selecting quoted text fails with 'selection' "exclusive"
Problem: Using a text object to select quoted text fails when 'selection' is set to "exclusive". (Guraga) Solution: Swap cursor and visual start position. (Christian Brabandt, closes #1687)
1 parent 8ad80de commit c5e2b04

File tree

3 files changed

+33
-10
lines changed

3 files changed

+33
-10
lines changed

src/search.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4364,16 +4364,27 @@ current_quote(
43644364
int selected_quote = FALSE; /* Has quote inside selection */
43654365
int i;
43664366

4367-
/* Correct cursor when 'selection' is exclusive */
4367+
/* Correct cursor when 'selection' is "exclusive". */
43684368
if (VIsual_active)
43694369
{
43704370
/* this only works within one line */
43714371
if (VIsual.lnum != curwin->w_cursor.lnum)
43724372
return FALSE;
43734373

43744374
vis_bef_curs = LT_POS(VIsual, curwin->w_cursor);
4375-
if (*p_sel == 'e' && vis_bef_curs)
4375+
if (*p_sel == 'e')
4376+
{
4377+
if (!vis_bef_curs)
4378+
{
4379+
/* VIsual needs to be start of Visual selection. */
4380+
pos_T t = curwin->w_cursor;
4381+
4382+
curwin->w_cursor = VIsual;
4383+
VIsual = t;
4384+
vis_bef_curs = TRUE;
4385+
}
43764386
dec_cursor();
4387+
}
43774388
vis_empty = EQUAL_POS(VIsual, curwin->w_cursor);
43784389
}
43794390

src/testdir/test_textobjects.vim

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ if !has('textobjects')
55
endif
66

77
set belloff=all
8-
function! CpoM(line, useM, expected)
8+
func CpoM(line, useM, expected)
99
new
1010

1111
if a:useM
@@ -29,16 +29,26 @@ function! CpoM(line, useM, expected)
2929
call assert_equal(getreg('"'), a:expected[2])
3030

3131
q!
32-
endfunction
32+
endfunc
3333

34-
function! Test_inner_block_without_cpo_M()
34+
func Test_inner_block_without_cpo_M()
3535
call CpoM('(red \(blue) green)', 0, ['red \(blue', 'red \(blue', ''])
36-
endfunction
36+
endfunc
3737

38-
function! Test_inner_block_with_cpo_M_left_backslash()
38+
func Test_inner_block_with_cpo_M_left_backslash()
3939
call CpoM('(red \(blue) green)', 1, ['red \(blue) green', 'blue', 'red \(blue) green'])
40-
endfunction
40+
endfunc
4141

42-
function! Test_inner_block_with_cpo_M_right_backslash()
42+
func Test_inner_block_with_cpo_M_right_backslash()
4343
call CpoM('(red (blue\) green)', 1, ['red (blue\) green', 'blue\', 'red (blue\) green'])
44-
endfunction
44+
endfunc
45+
46+
func Test_quote_selection_selection_exclusive()
47+
new
48+
call setline(1, "a 'bcde' f")
49+
set selection=exclusive
50+
exe "norm! fdvhi'y"
51+
call assert_equal('bcde', @")
52+
set selection&vim
53+
bw!
54+
endfunc

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -764,6 +764,8 @@ static char *(features[]) =
764764

765765
static int included_patches[] =
766766
{ /* Add new patch number below this line */
767+
/**/
768+
622,
767769
/**/
768770
621,
769771
/**/

0 commit comments

Comments
 (0)