diff options
author | Bram Moolenaar <Bram@vim.org> | 2019-03-07 11:25:32 +0100 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2019-03-07 11:25:32 +0100 |
commit | 19a66858a5e3fedadc371321834507c34e2dfb18 (patch) | |
tree | 6fca21cc4c5fcb7cfd73faaea55cb152272da49f | |
parent | d5a5886ce90a30efc830b0053472735c5bbb4b0f (diff) | |
download | vim-git-19a66858a5e3fedadc371321834507c34e2dfb18.tar.gz |
patch 8.1.0998: getcurpos() unexpectedly changes "curswant"v8.1.0998
Problem: getcurpos() unexpectedly changes "curswant".
Solution: Save and restore "curswant". (closes #4069)
-rw-r--r-- | src/evalfunc.c | 14 | ||||
-rw-r--r-- | src/testdir/test_visual.vim | 15 | ||||
-rw-r--r-- | src/version.c | 2 |
3 files changed, 27 insertions, 4 deletions
diff --git a/src/evalfunc.c b/src/evalfunc.c index f59574d48..f5d1da73b 100644 --- a/src/evalfunc.c +++ b/src/evalfunc.c @@ -5474,9 +5474,23 @@ getpos_both( (varnumber_T)0); if (getcurpos) { + int save_set_curswant = curwin->w_set_curswant; + colnr_T save_curswant = curwin->w_curswant; + colnr_T save_virtcol = curwin->w_virtcol; + update_curswant(); list_append_number(l, curwin->w_curswant == MAXCOL ? (varnumber_T)MAXCOL : (varnumber_T)curwin->w_curswant + 1); + + // Do not change "curswant", as it is unexpected that a get + // function has a side effect. + if (save_set_curswant) + { + curwin->w_set_curswant = save_set_curswant; + curwin->w_curswant = save_curswant; + curwin->w_virtcol = save_virtcol; + curwin->w_valid &= ~VALID_VIRTCOL; + } } } else diff --git a/src/testdir/test_visual.vim b/src/testdir/test_visual.vim index 77064bab2..abf131c38 100644 --- a/src/testdir/test_visual.vim +++ b/src/testdir/test_visual.vim @@ -1,8 +1,4 @@ " Tests for various Visual mode. -if !has('visual') - finish -endif - func Test_block_shift_multibyte() " Uses double-wide character. @@ -397,3 +393,14 @@ func Test_Visual_paragraph_textobject() bwipe! endfunc + +func Test_curswant_not_changed() + new + call setline(1, ['one', 'two']) + au InsertLeave * call getcurpos() + call feedkeys("gg0\<C-V>jI123 \<Esc>j", 'xt') + call assert_equal([0, 2, 1, 0, 1], getcurpos()) + + bwipe! + au! InsertLeave +endfunc diff --git a/src/version.c b/src/version.c index 539a1e10d..e57b5762b 100644 --- a/src/version.c +++ b/src/version.c @@ -780,6 +780,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 998, +/**/ 997, /**/ 996, |