]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.2.0923: tabpage: closing a tab page loses the alternate tab page v9.2.0923
authorHirohito Higashi <h.east.727@gmail.com>
Fri, 7 Aug 2026 20:09:30 +0000 (20:09 +0000)
committerChristian Brabandt <cb@256bit.org>
Fri, 7 Aug 2026 20:09:30 +0000 (20:09 +0000)
Problem:  Closing the current tab page resets the alternate tab page, even
          when that is another tab page which still exists, so that
          CTRL-Tab stops working (igorlfs).
Solution: Restore the last used tab page after entering another one to
          close the current one (Hirohito Higashi).

related: #20965
closes:  #20973

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Signed-off-by: Hirohito Higashi <h.east.727@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
src/testdir/test_tabpage.vim
src/version.c
src/window.c

index 05c56696733bbed60c805b7f7bffb669480a427d..e3749cf04215398d6358c79f1364d8a871d6ff32 100644 (file)
@@ -942,6 +942,23 @@ func Test_lastused_tabpage()
   tabonly!
 endfunc
 
+" Closing a tab page must keep the last used tab page when it is another one.
+func Test_lastused_tabpage_close()
+  tabonly!
+  tabnew
+  tabnew
+  tabfirst
+  tablast
+  call assert_equal(1, tabpagenr('#'))
+
+  tabclose
+  call assert_equal(1, tabpagenr('#'))
+  call feedkeys("g\<Tab>", "xt")
+  call assert_equal(1, tabpagenr())
+
+  tabonly!
+endfunc
+
 " Test for tabpage allocation failure
 func Test_tabpage_alloc_failure()
   call test_alloc_fail(GetAllocId('newtabpage_tvars'), 0, 0)
index 5f5600db747078ac96a24eb6f1efde3c5e335eee..d1a1f6689e5cdcc43ceac72dde0f27846c23fb0f 100644 (file)
@@ -763,6 +763,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    923,
 /**/
     922,
 /**/
index 8ac5b8f5ea0590cbda2afd2658773991b7b3ff88..4d4cfab4486b35546d6fe15dffa4bc5dc295a685 100644 (file)
@@ -2665,6 +2665,7 @@ close_last_window_tabpage(
        return FALSE;
 
     buf_T      *old_curbuf = curbuf;
+    tabpage_T  *save_lastused = lastused_tabpage;
 
     /*
      * Closing the last window in a tab page.  First go to another tab
@@ -2682,6 +2683,11 @@ close_last_window_tabpage(
     // to the other tab page.
     if (valid_tabpage(prev_curtab) && prev_curtab->tp_firstwin == win)
        win_close_othertab(win, free_buf, prev_curtab);
+
+    // Entering the other tab page made the closed one the last used tab page.
+    // Restore the previous one when it is still there.
+    if (valid_tabpage(save_lastused) && save_lastused != curtab)
+       lastused_tabpage = save_lastused;
 #ifdef FEAT_JOB_CHANNEL
     entering_window(curwin);
 #endif