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

b47fbb4083
This commit is contained in:
zeertzjq 2024-02-13 07:27:27 +08:00 committed by GitHub
parent 94085cfce8
commit 2493fd020d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 22 additions and 1 deletions

View File

@ -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;
}
}
}

View File

@ -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