summaryrefslogtreecommitdiffstats
path: root/src/window.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/window.c')
-rw-r--r--src/window.c22
1 files changed, 15 insertions, 7 deletions
diff --git a/src/window.c b/src/window.c
index 73229059ea..c87cce0016 100644
--- a/src/window.c
+++ b/src/window.c
@@ -3782,15 +3782,23 @@ win_altframe(
static tabpage_T *
alt_tabpage(void)
{
- tabpage_T *tp;
+ tabpage_T *tp = NULL;
+ int forward;
- // Use the next tab page if possible.
- if (curtab->tp_next != NULL)
- return curtab->tp_next;
+ // Use the last accessed tab page, if possible.
+ if ((tcl_flags & TCL_USELAST) && valid_tabpage(lastused_tabpage))
+ return lastused_tabpage;
+
+ // Use the previous tab page, if possible.
+ forward = curtab->tp_next != NULL &&
+ ((tcl_flags & TCL_LEFT) == 0 || curtab == first_tabpage);
+
+ if (forward)
+ tp = curtab->tp_next;
+ else
+ for (tp = first_tabpage; tp->tp_next != curtab; tp = tp->tp_next)
+ ;
- // Find the last but one tab page.
- for (tp = first_tabpage; tp->tp_next != curtab; tp = tp->tp_next)
- ;
return tp;
}