From 2493fd020d6f294c78a87b0f7f35c0398b248f1f Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 13 Feb 2024 07:27:27 +0800 Subject: [PATCH] vim-patch:9.1.0102: settabvar() may change the last accessed tabpage (#27450) Problem: settabvar() may change the last accessed tabpage. Solution: Save and restore lastused_tabpage. (zeertzjq) closes: vim/vim#14017 https://github.com/vim/vim/commit/b47fbb40837512cdd2d8c25eaf9952154836b99d --- src/nvim/eval/vars.c | 6 +++++- test/old/testdir/test_tabpage.vim | 17 +++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/nvim/eval/vars.c b/src/nvim/eval/vars.c index e149796fac..e016c65d90 100644 --- a/src/nvim/eval/vars.c +++ b/src/nvim/eval/vars.c @@ -2090,6 +2090,7 @@ void f_settabvar(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) } tabpage_T *const save_curtab = curtab; + tabpage_T *const save_lu_tp = lastused_tabpage; goto_tabpage_tp(tp, false, false); const size_t varname_len = strlen(varname); @@ -2099,9 +2100,12 @@ void f_settabvar(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) set_var(tabvarname, varname_len + 2, varp, true); xfree(tabvarname); - // Restore current tabpage. + // Restore current tabpage and last accessed tabpage. if (valid_tabpage(save_curtab)) { goto_tabpage_tp(save_curtab, false, false); + if (valid_tabpage(save_lu_tp)) { + lastused_tabpage = save_lu_tp; + } } } diff --git a/test/old/testdir/test_tabpage.vim b/test/old/testdir/test_tabpage.vim index adb9e13269..0f038c8bee 100644 --- a/test/old/testdir/test_tabpage.vim +++ b/test/old/testdir/test_tabpage.vim @@ -995,4 +995,21 @@ func Test_tabpage_drop_tabmove() bwipe! endfunc +" Test that settabvar() shouldn't change the last accessed tabpage. +func Test_lastused_tabpage_settabvar() + tabonly! + tabnew + tabnew + tabnew + call assert_equal(3, tabpagenr('#')) + + call settabvar(2, 'myvar', 'tabval') + call assert_equal('tabval', gettabvar(2, 'myvar')) + call assert_equal(3, tabpagenr('#')) + + bwipe! + bwipe! + bwipe! +endfunc + " vim: shiftwidth=2 sts=2 expandtab