tabpage: track last-used tabpage #11626

In a multi-window scenario, it is possible to return focus to the last
accessed window via n_CTRL-W_p.  However, in the case of a multi-tab
scenario, there was previously no way to return focus to the last
accessed *tab*.  Here, that ability is added via n_g<tab>.

Additionally, the index of the previous tab is exposed via
tabpagenr('#'), mirroring the existing functionality of winnr('#').
This commit is contained in:
butwerenotthereyet
2020-01-02 06:06:11 -08:00
committed by Justin M. Keyes
parent 2c62b2fc56
commit cbc8d72fde
7 changed files with 502 additions and 9 deletions

View File

@@ -519,6 +519,10 @@ wingotofile:
do_nv_ident('g', xchar);
break;
case TAB:
goto_tabpage_lastused();
break;
case 'f': /* CTRL-W gf: "gf" in a new tab page */
case 'F': /* CTRL-W gF: "gF" in a new tab page */
cmdmod.tab = tabpage_index(curtab) + 1;
@@ -3691,6 +3695,10 @@ void free_tabpage(tabpage_T *tp)
hash_init(&tp->tp_vars->dv_hashtab);
unref_var_dict(tp->tp_vars);
if (tp == lastused_tabpage) {
lastused_tabpage = NULL;
}
xfree(tp->tp_localdir);
xfree(tp);
}
@@ -3750,6 +3758,8 @@ int win_new_tabpage(int after, char_u *filename)
tabpage_check_windows(tp);
lastused_tabpage = tp;
apply_autocmds(EVENT_WINNEW, NULL, NULL, false, curbuf);
apply_autocmds(EVENT_WINENTER, NULL, NULL, false, curbuf);
apply_autocmds(EVENT_TABNEW, filename, filename, false, curbuf);
@@ -3976,6 +3986,7 @@ static void enter_tabpage(tabpage_T *tp, buf_T *old_curbuf, int trigger_enter_au
if (curtab->tp_old_Columns != Columns && starting == 0)
shell_new_columns(); /* update window widths */
lastused_tabpage = old_curtab;
/* Apply autocommands after updating the display, when 'rows' and
* 'columns' have been set correctly. */
@@ -4095,6 +4106,14 @@ void goto_tabpage_tp(tabpage_T *tp, int trigger_enter_autocmds, int trigger_leav
}
}
// Go to the last accessed tab page, if there is one.
void goto_tabpage_lastused(void)
{
if (valid_tabpage(lastused_tabpage)) {
goto_tabpage_tp(lastused_tabpage, true, true);
}
}
/*
* Enter window "wp" in tab page "tp".
* Also updates the GUI tab.