Mercurial > vim
diff src/evalfunc.c @ 15985:e91750e8adb5 v8.1.0998
patch 8.1.0998: getcurpos() unexpectedly changes "curswant"
commit https://github.com/vim/vim/commit/19a66858a5e3fedadc371321834507c34e2dfb18
Author: Bram Moolenaar <Bram@vim.org>
Date: Thu Mar 7 11:25:32 2019 +0100
patch 8.1.0998: getcurpos() unexpectedly changes "curswant"
Problem: getcurpos() unexpectedly changes "curswant".
Solution: Save and restore "curswant". (closes https://github.com/vim/vim/issues/4069)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Thu, 07 Mar 2019 11:30:15 +0100 |
parents | 72987a858c96 |
children | 012f03e583e2 |
line wrap: on
line diff
--- 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