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>
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)
static int included_patches[] =
{ /* Add new patch number below this line */
+/**/
+ 923,
/**/
922,
/**/
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
// 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