From: Hirohito Higashi Date: Fri, 7 Aug 2026 20:09:30 +0000 (+0000) Subject: patch 9.2.0923: tabpage: closing a tab page loses the alternate tab page X-Git-Tag: v9.2.0923^0 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=a05bd64c1dcde65006997efe0ff5ae6b8a9aa382;p=thirdparty%2Fvim.git patch 9.2.0923: tabpage: closing a tab page loses the alternate tab page 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) Signed-off-by: Hirohito Higashi Signed-off-by: Christian Brabandt --- diff --git a/src/testdir/test_tabpage.vim b/src/testdir/test_tabpage.vim index 05c5669673..e3749cf042 100644 --- a/src/testdir/test_tabpage.vim +++ b/src/testdir/test_tabpage.vim @@ -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\", "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) diff --git a/src/version.c b/src/version.c index 5f5600db74..d1a1f6689e 100644 --- a/src/version.c +++ b/src/version.c @@ -763,6 +763,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ +/**/ + 923, /**/ 922, /**/ diff --git a/src/window.c b/src/window.c index 8ac5b8f5ea..4d4cfab448 100644 --- a/src/window.c +++ b/src/window.c @@ -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