diff --git a/src/testdir/test_mksession.vim b/src/testdir/test_mksession.vim
index bc41396..80bedfc 100644
--- a/src/testdir/test_mksession.vim
+++ b/src/testdir/test_mksession.vim
@@ -307,7 +307,6 @@ endfunc
endif
-
func Test_mksession_blank_windows()
split
split
@@ -323,6 +322,35 @@ func Test_mksession_blank_windows()
call delete('Xtest_mks.out')
endfunc
+func Test_mksession_tab_curwin()
+ only | tabonly
+
+ " tab with 2 windows
+ split
+ 2 wincmd w
+ tabnew
+
+ " tab with 3 windows
+ split | split
+ 3 wincmd w
+ tabnew
+
+ " tab with 4 windows
+ split | split | split
+ 3 wincmd w
+ tabnew
+
+ mksession! Xtest_mks.out
+ source Xtest_mks.out
+ call assert_equal(2, tabpagewinnr(1))
+ call assert_equal(3, tabpagewinnr(2))
+ call assert_equal(3, tabpagewinnr(3))
+ call assert_equal(1, tabpagewinnr(4))
+ call delete('Xtest_mks.out')
+
+ %bw!
+endfunc
+
if has('terminal')
func Test_mksession_terminal_shell()
The patch below fixes the problem and cleans up some of the code a bit.
diff --git a/src/ex_docmd.c b/src/ex_docmd.c
index 16f5059..3c41b3d 100644
--- a/src/ex_docmd.c
+++ b/src/ex_docmd.c
@@ -9727,6 +9727,7 @@ makeopens(
win_T *edited_win = NULL;
int tabnr;
int restore_stal = FALSE;
+ win_T *tab_curwin;
win_T *tab_firstwin;
frame_T *tab_topframe;
int cur_arg_idx = 0;
@@ -9842,7 +9843,8 @@ makeopens(
* Don't use goto_tabpage(), it may change directory and trigger
* autocommands.
*/
- tab_firstwin = firstwin; /* first window in tab page "tabnr" */
+ tab_curwin = curwin; // current window in tab page "tabnr"
+ tab_firstwin = firstwin; // first window in tab page "tabnr"
tab_topframe = topframe;
if ((ssop_flags & SSOP_TABPAGES))
{
@@ -9866,20 +9868,15 @@ makeopens(
{
tp = find_tabpage(tabnr);
+ // done all tab pages
if (tp == NULL)
- break; /* done all tab pages */
- if (tp == curtab)
- {
- tab_firstwin = firstwin;
- tab_topframe = topframe;
- }
- else
- {
- tab_firstwin = tp->tp_firstwin;
- tab_topframe = tp->tp_topframe;
- }
- if (tabnr > 1)
- need_tabnext = TRUE;
+ break;
+
+ tab_curwin = (tp == curtab) ? curwin : tp->tp_curwin;
+ tab_firstwin = (tp == curtab) ? firstwin : tp->tp_firstwin;
+ tab_topframe = (tp == curtab) ? topframe : tp->tp_topframe;
+
+ need_tabnext = (tabnr > 1);
}
/*
@@ -9938,7 +9935,7 @@ makeopens(
++nr;
else
restore_size = FALSE;
- if (curwin == wp)
+ if (tab_curwin == wp)
cnr = nr;
}
Thanks,
Jason Franklin
No, it does not fix that issue.
However, I'm not exactly sure that the issue referenced is a valid
complaint. It was my understanding that buffer numbers are simply id
numbers and shouldn't be relied upon for anything other than referencing
a particular buffer. The fact that the order changed shouldn't matter.
I'm not opposed to fixing this... I just don't get why it would be
important since the point of a session is to restore the views on all
of the files you were editing when the session was saved.
Am I wrong about this?
> Perhaps using :argadd works to create the buffers without actually
> opening them or any other side effects. Then later reset the
> argument list.
I think it's even trickier than using :argadd. For example...
vim --clean
:argadd test.txt
:e test.txt
Notice that you're now editing buffer #2. This breaks the previous
patch I submitted to avoid extra empty buffers when loading a session.
Also, consider the case where several buffers are open and the user opens
a session with :so Session.vim. Then, cycling through the buffers won't
work anyway because there will be several buffers open from before the
session was loaded.
I'm unable to come up with perfect solutions to these issues at this time.
However, the patch under discussion here seems obviously correct to me. The
test here does a nice job of proving that the fix works, and should pass in
all future changes to the session code to fix any of the other issues named
here.
-- Jason