From 72e304c3497c0286dca4fd87314abc0d0a1f43a5 Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Thu, 7 Mar 2019 22:11:26 -0500 Subject: vim-patch:8.1.0998: getcurpos() unexpectedly changes "curswant" Problem: getcurpos() unexpectedly changes "curswant". Solution: Save and restore "curswant". (closes vim/vim#4069) https://github.com/vim/vim/commit/19a66858a5e3fedadc371321834507c34e2dfb18 --- src/nvim/eval.c | 13 +++++++++++++ src/nvim/testdir/test_visual.vim | 15 +++++++++++---- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/nvim/eval.c b/src/nvim/eval.c index d18884ff07..7b6990e077 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -10086,10 +10086,23 @@ static void getpos_both(typval_T *argvars, typval_T *rettv, bool getcurpos) tv_list_append_number( l, (fp != NULL) ? (varnumber_T)fp->coladd : (varnumber_T)0); if (getcurpos) { + const int save_set_curswant = curwin->w_set_curswant; + const colnr_T save_curswant = curwin->w_curswant; + const colnr_T save_virtcol = curwin->w_virtcol; + update_curswant(); tv_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; + } } } diff --git a/src/nvim/testdir/test_visual.vim b/src/nvim/testdir/test_visual.vim index 4a143d665d..9e32f217ad 100644 --- a/src/nvim/testdir/test_visual.vim +++ b/src/nvim/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. @@ -318,3 +314,14 @@ func Test_Visual_sentence_textobject() bwipe! endfunc + +func Test_curswant_not_changed() + new + call setline(1, ['one', 'two']) + au InsertLeave * call getcurpos() + call feedkeys("gg0\jI123 \j", 'xt') + call assert_equal([0, 2, 1, 0, 1], getcurpos()) + + bwipe! + au! InsertLeave +endfunc -- cgit