]> granicus.if.org Git - vim/commitdiff
patch 8.1.0998: getcurpos() unexpectedly changes "curswant" v8.1.0998
authorBram Moolenaar <Bram@vim.org>
Thu, 7 Mar 2019 10:25:32 +0000 (11:25 +0100)
committerBram Moolenaar <Bram@vim.org>
Thu, 7 Mar 2019 10:25:32 +0000 (11:25 +0100)
Problem:    getcurpos() unexpectedly changes "curswant".
Solution:   Save and restore "curswant". (closes #4069)

src/evalfunc.c
src/testdir/test_visual.vim
src/version.c

index f59574d48f7900eaf0d3f2a80950be09e78ad382..f5d1da73b86a07fb7889af5a97a093ad80648821 100644 (file)
@@ -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
index 77064bab265ff0dbaef89a056763765b05a50eab..abf131c384df5ea04fc3c963fd5444bb7c0dbdc1 100644 (file)
@@ -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
index 539a1e10d48cb8c456881c7fbe361d40b3a79e2b..e57b5762b3284e50259ebfb5451295c08401ac13 100644 (file)
@@ -779,6 +779,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    998,
 /**/
     997,
 /**/