0
0
mirror of https://github.com/vim/vim.git synced 2025-07-26 11:04:33 -04:00

patch 9.1.0102: settabvar() may change the last accessed tabpage

Problem:  settabvar() may change the last accessed tabpage.
Solution: Save and restore lastused_tabpage.
          (zeertzjq)

closes: #14017

Signed-off-by: zeertzjq <zeertzjq@outlook.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
This commit is contained in:
zeertzjq 2024-02-12 22:50:26 +01:00 committed by Christian Brabandt
parent bd1232a1fa
commit b47fbb4083
No known key found for this signature in database
GPG Key ID: F3F92DA383FDDE09
3 changed files with 26 additions and 1 deletions

View File

@ -4843,6 +4843,7 @@ f_settabvar(typval_T *argvars, typval_T *rettv UNUSED)
{ {
tabpage_T *save_curtab; tabpage_T *save_curtab;
tabpage_T *tp; tabpage_T *tp;
tabpage_T *save_lu_tp;
char_u *varname, *tabvarname; char_u *varname, *tabvarname;
typval_T *varp; typval_T *varp;
@ -4862,6 +4863,7 @@ f_settabvar(typval_T *argvars, typval_T *rettv UNUSED)
return; return;
save_curtab = curtab; save_curtab = curtab;
save_lu_tp = lastused_tabpage;
goto_tabpage_tp(tp, FALSE, FALSE); goto_tabpage_tp(tp, FALSE, FALSE);
tabvarname = alloc(STRLEN(varname) + 3); tabvarname = alloc(STRLEN(varname) + 3);
@ -4873,9 +4875,13 @@ f_settabvar(typval_T *argvars, typval_T *rettv UNUSED)
vim_free(tabvarname); vim_free(tabvarname);
} }
// Restore current tabpage // Restore current tabpage and last accessed tabpage.
if (valid_tabpage(save_curtab)) if (valid_tabpage(save_curtab))
{
goto_tabpage_tp(save_curtab, FALSE, FALSE); goto_tabpage_tp(save_curtab, FALSE, FALSE);
if (valid_tabpage(save_lu_tp))
lastused_tabpage = save_lu_tp;
}
} }
/* /*

View File

@ -993,4 +993,21 @@ func Test_tabpage_drop_tabmove()
bwipe! bwipe!
endfunc 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 " vim: shiftwidth=2 sts=2 expandtab

View File

@ -704,6 +704,8 @@ static char *(features[]) =
static int included_patches[] = static int included_patches[] =
{ /* Add new patch number below this line */ { /* Add new patch number below this line */
/**/
102,
/**/ /**/
101, 101,
/**/ /**/