Skip to content

Commit 19a6685

Browse files
committed
patch 8.1.0998: getcurpos() unexpectedly changes "curswant"
Problem: getcurpos() unexpectedly changes "curswant". Solution: Save and restore "curswant". (closes #4069)
1 parent d5a5886 commit 19a6685

3 files changed

Lines changed: 27 additions & 4 deletions

File tree

src/evalfunc.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5474,9 +5474,23 @@ getpos_both(
54745474
(varnumber_T)0);
54755475
if (getcurpos)
54765476
{
5477+
int save_set_curswant = curwin->w_set_curswant;
5478+
colnr_T save_curswant = curwin->w_curswant;
5479+
colnr_T save_virtcol = curwin->w_virtcol;
5480+
54775481
update_curswant();
54785482
list_append_number(l, curwin->w_curswant == MAXCOL ?
54795483
(varnumber_T)MAXCOL : (varnumber_T)curwin->w_curswant + 1);
5484+
5485+
// Do not change "curswant", as it is unexpected that a get
5486+
// function has a side effect.
5487+
if (save_set_curswant)
5488+
{
5489+
curwin->w_set_curswant = save_set_curswant;
5490+
curwin->w_curswant = save_curswant;
5491+
curwin->w_virtcol = save_virtcol;
5492+
curwin->w_valid &= ~VALID_VIRTCOL;
5493+
}
54805494
}
54815495
}
54825496
else

src/testdir/test_visual.vim

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
11
" Tests for various Visual mode.
2-
if !has('visual')
3-
finish
4-
endif
5-
62

73
func Test_block_shift_multibyte()
84
" Uses double-wide character.
@@ -397,3 +393,14 @@ func Test_Visual_paragraph_textobject()
397393

398394
bwipe!
399395
endfunc
396+
397+
func Test_curswant_not_changed()
398+
new
399+
call setline(1, ['one', 'two'])
400+
au InsertLeave * call getcurpos()
401+
call feedkeys("gg0\<C-V>jI123 \<Esc>j", 'xt')
402+
call assert_equal([0, 2, 1, 0, 1], getcurpos())
403+
404+
bwipe!
405+
au! InsertLeave
406+
endfunc

src/version.c

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

780780
static int included_patches[] =
781781
{ /* Add new patch number below this line */
782+
/**/
783+
998,
782784
/**/
783785
997,
784786
/**/

0 commit comments

Comments
 (0)