aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorbutwerenotthereyet <58348703+butwerenotthereyet@users.noreply.github.com>2020-01-02 06:06:11 -0800
committerJustin M. Keyes <justinkz@gmail.com>2020-01-02 06:06:11 -0800
commitcbc8d72fde4b19176028490934ff7a447afe523c (patch)
tree80c962c8c65b356e55b9a55e0f67c1ba2b24b78d /src
parent2c62b2fc56b6b86a930356ccf48ba8fb189a7654 (diff)
downloadrneovim-cbc8d72fde4b19176028490934ff7a447afe523c.tar.gz
rneovim-cbc8d72fde4b19176028490934ff7a447afe523c.tar.bz2
rneovim-cbc8d72fde4b19176028490934ff7a447afe523c.zip
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('#').
Diffstat (limited to 'src')
-rw-r--r--src/nvim/eval.c4
-rw-r--r--src/nvim/globals.h1
-rw-r--r--src/nvim/normal.c20
-rw-r--r--src/nvim/window.c19
4 files changed, 38 insertions, 6 deletions
diff --git a/src/nvim/eval.c b/src/nvim/eval.c
index 65f029649c..cf4d3af232 100644
--- a/src/nvim/eval.c
+++ b/src/nvim/eval.c
@@ -18172,6 +18172,10 @@ static void f_tabpagenr(typval_T *argvars, typval_T *rettv, FunPtr fptr)
if (arg != NULL) {
if (strcmp(arg, "$") == 0) {
nr = tabpage_index(NULL) - 1;
+ } else if (strcmp(arg, "#") == 0) {
+ nr = valid_tabpage(lastused_tabpage)
+ ? tabpage_index(lastused_tabpage)
+ : nr;
} else {
EMSG2(_(e_invexpr2), arg);
}
diff --git a/src/nvim/globals.h b/src/nvim/globals.h
index c6ab574a0f..148ab0a02b 100644
--- a/src/nvim/globals.h
+++ b/src/nvim/globals.h
@@ -459,6 +459,7 @@ EXTERN frame_T *topframe; /* top of the window frame tree */
* one in the list, "curtab" is the current one.
*/
EXTERN tabpage_T *first_tabpage;
+EXTERN tabpage_T *lastused_tabpage;
EXTERN tabpage_T *curtab;
EXTERN int redraw_tabline INIT(= FALSE); /* need to redraw tabline */
diff --git a/src/nvim/normal.c b/src/nvim/normal.c
index 9c707a6fdc..d0b9fd4589 100644
--- a/src/nvim/normal.c
+++ b/src/nvim/normal.c
@@ -6312,9 +6312,7 @@ static void nv_gomark(cmdarg_T *cap)
}
}
-/*
- * Handle CTRL-O, CTRL-I, "g;" and "g," commands.
- */
+// Handle CTRL-O, CTRL-I, "g;", "g,", and "CTRL-Tab" commands.
static void nv_pcmark(cmdarg_T *cap)
{
pos_T *pos;
@@ -6322,11 +6320,16 @@ static void nv_pcmark(cmdarg_T *cap)
const bool old_KeyTyped = KeyTyped; // getting file may reset it
if (!checkclearopq(cap->oap)) {
- if (cap->cmdchar == 'g')
+ if (cap->cmdchar == TAB && mod_mask == MOD_MASK_CTRL) {
+ goto_tabpage_lastused();
+ return;
+ }
+ if (cap->cmdchar == 'g') {
pos = movechangelist((int)cap->count1);
- else
+ } else {
pos = movemark((int)cap->count1);
- if (pos == (pos_T *)-1) { /* jump to other file */
+ }
+ if (pos == (pos_T *)-1) { // jump to other file
curwin->w_set_curswant = true;
check_cursor();
} else if (pos != NULL) /* can jump */
@@ -7059,6 +7062,11 @@ static void nv_g_cmd(cmdarg_T *cap)
if (!checkclearop(oap))
goto_tabpage(-(int)cap->count1);
break;
+ case TAB:
+ if (!checkclearop(oap)) {
+ goto_tabpage_lastused();
+ }
+ break;
case '+':
case '-': /* "g+" and "g-": undo or redo along the timeline */
diff --git a/src/nvim/window.c b/src/nvim/window.c
index 79d7a8acba..4d105dd11e 100644
--- a/src/nvim/window.c
+++ b/src/nvim/window.c
@@ -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.