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

Commit: 
https://github.com/vim/vim/commit/b47fbb40837512cdd2d8c25eaf9952154836b99d
Author: zeertzjq <[email protected]>
Date:   Mon Feb 12 22:50:26 2024 +0100

    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 <[email protected]>
    Signed-off-by: Christian Brabandt <[email protected]>

diff --git a/src/evalvars.c b/src/evalvars.c
index 0a84afdaa..856e47511 100644
--- a/src/evalvars.c
+++ b/src/evalvars.c
@@ -4843,6 +4843,7 @@ f_settabvar(typval_T *argvars, typval_T *rettv UNUSED)
 {
     tabpage_T  *save_curtab;
     tabpage_T  *tp;
+    tabpage_T  *save_lu_tp;
     char_u     *varname, *tabvarname;
     typval_T   *varp;
 
@@ -4862,6 +4863,7 @@ f_settabvar(typval_T *argvars, typval_T *rettv UNUSED)
        return;
 
     save_curtab = curtab;
+    save_lu_tp = lastused_tabpage;
     goto_tabpage_tp(tp, FALSE, FALSE);
 
     tabvarname = alloc(STRLEN(varname) + 3);
@@ -4873,9 +4875,13 @@ f_settabvar(typval_T *argvars, typval_T *rettv UNUSED)
        vim_free(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/src/testdir/test_tabpage.vim b/src/testdir/test_tabpage.vim
index 94f695323..a531f1933 100644
--- a/src/testdir/test_tabpage.vim
+++ b/src/testdir/test_tabpage.vim
@@ -993,4 +993,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
diff --git a/src/version.c b/src/version.c
index fec82525d..e20b4270a 100644
--- a/src/version.c
+++ b/src/version.c
@@ -704,6 +704,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    102,
 /**/
     101,
 /**/

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/E1rZeLM-00BQhD-Kc%40256bit.org.

Raspunde prin e-mail lui