mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
vim-patch:8.2.4850: mksession mixes up "tabpages" and "curdir" arguments
Problem: Mksession mixes up "tabpages" and "curdir" arguments.
Solution: Correct logic for storing tabpage in session. (closes vim/vim#10312)
d7c9564d8d
Co-authored-by: LemonBoy <thatlemon@gmail.com>
This commit is contained in:
parent
3d9593523d
commit
c23c44f845
@ -537,7 +537,6 @@ static int makeopens(FILE *fd, char *dirnow)
|
|||||||
win_T *wp;
|
win_T *wp;
|
||||||
char *sname;
|
char *sname;
|
||||||
win_T *edited_win = NULL;
|
win_T *edited_win = NULL;
|
||||||
int tabnr;
|
|
||||||
win_T *tab_firstwin;
|
win_T *tab_firstwin;
|
||||||
frame_T *tab_topframe;
|
frame_T *tab_topframe;
|
||||||
int cur_arg_idx = 0;
|
int cur_arg_idx = 0;
|
||||||
@ -644,14 +643,10 @@ static int makeopens(FILE *fd, char *dirnow)
|
|||||||
restore_stal = true;
|
restore_stal = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// For each tab:
|
|
||||||
// - Put windows for each tab, when "tabpages" is in 'sessionoptions'.
|
|
||||||
// - Don't use goto_tabpage(), it may change CWD and trigger autocommands.
|
|
||||||
tab_firstwin = firstwin; // First window in tab page "tabnr".
|
|
||||||
tab_topframe = topframe;
|
|
||||||
if ((ssop_flags & SSOP_TABPAGES)) {
|
if ((ssop_flags & SSOP_TABPAGES)) {
|
||||||
// Similar to ses_win_rec() below, populate the tab pages first so
|
// "tabpages" is in 'sessionoptions': Similar to ses_win_rec() below,
|
||||||
// later local options won't be copied to the new tabs.
|
// populate the tab pages first so later local options won't be copied
|
||||||
|
// to the new tabs.
|
||||||
FOR_ALL_TABS(tp) {
|
FOR_ALL_TABS(tp) {
|
||||||
// Use `bufhidden=wipe` to remove empty "placeholder" buffers once
|
// Use `bufhidden=wipe` to remove empty "placeholder" buffers once
|
||||||
// they are not needed. This prevents creating extra buffers (see
|
// they are not needed. This prevents creating extra buffers (see
|
||||||
@ -665,15 +660,17 @@ static int makeopens(FILE *fd, char *dirnow)
|
|||||||
return FAIL;
|
return FAIL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (tabnr = 1;; tabnr++) {
|
|
||||||
tabpage_T *tp = find_tabpage(tabnr);
|
|
||||||
if (tp == NULL) {
|
|
||||||
break; // done all tab pages
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// Assume "tabpages" is in 'sessionoptions'. If not then we only do
|
||||||
|
// "curtab" and bail out of the loop.
|
||||||
|
FOR_ALL_TABS(tp) {
|
||||||
bool need_tabnext = false;
|
bool need_tabnext = false;
|
||||||
int cnr = 1;
|
int cnr = 1;
|
||||||
|
|
||||||
|
// May repeat putting Windows for each tab, when "tabpages" is in
|
||||||
|
// 'sessionoptions'.
|
||||||
|
// Don't use goto_tabpage(), it may change directory and trigger
|
||||||
|
// autocommands.
|
||||||
if ((ssop_flags & SSOP_TABPAGES)) {
|
if ((ssop_flags & SSOP_TABPAGES)) {
|
||||||
if (tp == curtab) {
|
if (tp == curtab) {
|
||||||
tab_firstwin = firstwin;
|
tab_firstwin = firstwin;
|
||||||
@ -682,9 +679,13 @@ static int makeopens(FILE *fd, char *dirnow)
|
|||||||
tab_firstwin = tp->tp_firstwin;
|
tab_firstwin = tp->tp_firstwin;
|
||||||
tab_topframe = tp->tp_topframe;
|
tab_topframe = tp->tp_topframe;
|
||||||
}
|
}
|
||||||
if (tabnr > 1) {
|
if (tp != first_tabpage) {
|
||||||
need_tabnext = true;
|
need_tabnext = true;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
tp = curtab;
|
||||||
|
tab_firstwin = firstwin;
|
||||||
|
tab_topframe = topframe;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Before creating the window layout, try loading one file. If this
|
// Before creating the window layout, try loading one file. If this
|
||||||
@ -770,7 +771,7 @@ static int makeopens(FILE *fd, char *dirnow)
|
|||||||
// Restore the tab-local working directory if specified
|
// Restore the tab-local working directory if specified
|
||||||
// Do this before the windows, so that the window-local directory can
|
// Do this before the windows, so that the window-local directory can
|
||||||
// override the tab-local directory.
|
// override the tab-local directory.
|
||||||
if (tp != NULL && tp->tp_localdir != NULL && (ssop_flags & SSOP_CURDIR)) {
|
if ((ssop_flags & SSOP_CURDIR) && tp->tp_localdir != NULL) {
|
||||||
if (fputs("tcd ", fd) < 0
|
if (fputs("tcd ", fd) < 0
|
||||||
|| ses_put_fname(fd, tp->tp_localdir, &ssop_flags) == FAIL
|
|| ses_put_fname(fd, tp->tp_localdir, &ssop_flags) == FAIL
|
||||||
|| put_eol(fd) == FAIL) {
|
|| put_eol(fd) == FAIL) {
|
||||||
|
@ -803,6 +803,35 @@ func Test_mksession_sesdir()
|
|||||||
call delete('Xproj', 'rf')
|
call delete('Xproj', 'rf')
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
|
" Test for saving and restoring the tab-local working directory when there is
|
||||||
|
" only a single tab and 'tabpages' is not in 'sessionoptions'.
|
||||||
|
func Test_mksession_tcd_single_tabs()
|
||||||
|
only | tabonly
|
||||||
|
|
||||||
|
let save_cwd = getcwd()
|
||||||
|
set sessionoptions-=tabpages
|
||||||
|
set sessionoptions+=curdir
|
||||||
|
call mkdir('Xtopdir1')
|
||||||
|
call mkdir('Xtopdir2')
|
||||||
|
|
||||||
|
" There are two tab pages, the current one has local cwd set to 'Xtopdir2'.
|
||||||
|
exec 'tcd ' .. save_cwd .. '/Xtopdir1'
|
||||||
|
tabnew
|
||||||
|
exec 'tcd ' .. save_cwd .. '/Xtopdir2'
|
||||||
|
mksession! Xtest_tcd_single
|
||||||
|
|
||||||
|
source Xtest_tcd_single
|
||||||
|
" call assert_equal(2, haslocaldir())
|
||||||
|
call assert_equal(1, haslocaldir(-1))
|
||||||
|
call assert_equal('Xtopdir2', fnamemodify(getcwd(-1, 0), ':t'))
|
||||||
|
%bwipe
|
||||||
|
|
||||||
|
set sessionoptions&
|
||||||
|
call chdir(save_cwd)
|
||||||
|
call delete('Xtopdir1', 'rf')
|
||||||
|
call delete('Xtopdir2', 'rf')
|
||||||
|
endfunc
|
||||||
|
|
||||||
" Test for storing the 'lines' and 'columns' settings
|
" Test for storing the 'lines' and 'columns' settings
|
||||||
func Test_mksession_resize()
|
func Test_mksession_resize()
|
||||||
mksession! Xtest_mks1.out
|
mksession! Xtest_mks1.out
|
||||||
|
Loading…
Reference in New Issue
Block a user