mirror of
https://github.com/neovim/neovim.git
synced 2025-09-13 06:48:17 +00:00
vim-patch:8.1.0149: session is wrong with multiple tabs when :lcd was used
Problem: The generated sessions file does not restore tabs properly if :lcd
was used in one of them.
Solution: Create the tab pages before setting the directory. (Yee Cheng
Chin, closes vim/vim#3152)
26d4b896a7
This commit is contained in:
@@ -4769,10 +4769,8 @@ static void ex_abclear(exarg_T *eap)
|
|||||||
|
|
||||||
static void ex_autocmd(exarg_T *eap)
|
static void ex_autocmd(exarg_T *eap)
|
||||||
{
|
{
|
||||||
/*
|
// Disallow autocommands from .exrc and .vimrc in current
|
||||||
* Disallow auto commands from .exrc and .vimrc in current
|
// directory for security reasons.
|
||||||
* directory for security reasons.
|
|
||||||
*/
|
|
||||||
if (secure) {
|
if (secure) {
|
||||||
secure = 2;
|
secure = 2;
|
||||||
eap->errmsg = e_curdir;
|
eap->errmsg = e_curdir;
|
||||||
|
@@ -526,8 +526,12 @@ static int makeopens(FILE *fd, char_u *dirnow)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Close all windows but one.
|
// Close all windows and tabs but one.
|
||||||
PUTLINE_FAIL("silent only");
|
PUTLINE_FAIL("silent only");
|
||||||
|
if ((ssop_flags & SSOP_TABPAGES)
|
||||||
|
&& put_line(fd, "silent tabonly") == FAIL) {
|
||||||
|
return FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Now a :cd command to the session directory or the current directory
|
// Now a :cd command to the session directory or the current directory
|
||||||
@@ -606,13 +610,34 @@ static int makeopens(FILE *fd, char_u *dirnow)
|
|||||||
//
|
//
|
||||||
tab_firstwin = firstwin; // First window in tab page "tabnr".
|
tab_firstwin = firstwin; // First window in tab page "tabnr".
|
||||||
tab_topframe = topframe;
|
tab_topframe = topframe;
|
||||||
|
if ((ssop_flags & SSOP_TABPAGES)) {
|
||||||
|
// Similar to ses_win_rec() below, populate the tab pages first so
|
||||||
|
// later local options won't be copied to the new tabs.
|
||||||
|
for (tabnr = 1;; tabnr++) {
|
||||||
|
const tabpage_T *const tp = find_tabpage(tabnr);
|
||||||
|
|
||||||
|
if (tp == NULL) { // done all tab pages
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (tabnr > 1 && put_line(fd, "tabnew") == FAIL) {
|
||||||
|
return FAIL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const int num_tabs = tabnr - 1;
|
||||||
|
if (num_tabs > 1
|
||||||
|
&& (fprintf(fd, "tabnext -%d", num_tabs - 1) < 0
|
||||||
|
|| put_eol(fd) == FAIL)) {
|
||||||
|
return FAIL;
|
||||||
|
}
|
||||||
|
}
|
||||||
for (tabnr = 1;; tabnr++) {
|
for (tabnr = 1;; tabnr++) {
|
||||||
tabpage_T *tp = find_tabpage(tabnr);
|
tabpage_T *tp = find_tabpage(tabnr);
|
||||||
if (tp == NULL) {
|
if (tp == NULL) {
|
||||||
break; // done all tab pages
|
break; // done all tab pages
|
||||||
}
|
}
|
||||||
|
|
||||||
int need_tabnew = false;
|
bool need_tabnext = false;
|
||||||
int cnr = 1;
|
int cnr = 1;
|
||||||
|
|
||||||
if ((ssop_flags & SSOP_TABPAGES)) {
|
if ((ssop_flags & SSOP_TABPAGES)) {
|
||||||
@@ -624,7 +649,7 @@ static int makeopens(FILE *fd, char_u *dirnow)
|
|||||||
tab_topframe = tp->tp_topframe;
|
tab_topframe = tp->tp_topframe;
|
||||||
}
|
}
|
||||||
if (tabnr > 1) {
|
if (tabnr > 1) {
|
||||||
need_tabnew = true;
|
need_tabnext = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -639,11 +664,15 @@ static int makeopens(FILE *fd, char_u *dirnow)
|
|||||||
&& !bt_help(wp->w_buffer)
|
&& !bt_help(wp->w_buffer)
|
||||||
&& !bt_nofile(wp->w_buffer)
|
&& !bt_nofile(wp->w_buffer)
|
||||||
) {
|
) {
|
||||||
if (fputs(need_tabnew ? "tabedit " : "edit ", fd) < 0
|
if (need_tabnext && put_line(fd, "tabnext") == FAIL) {
|
||||||
|
return FAIL;
|
||||||
|
}
|
||||||
|
need_tabnext = false;
|
||||||
|
|
||||||
|
if (fputs("edit ", fd) < 0
|
||||||
|| ses_fname(fd, wp->w_buffer, &ssop_flags, true) == FAIL) {
|
|| ses_fname(fd, wp->w_buffer, &ssop_flags, true) == FAIL) {
|
||||||
return FAIL;
|
return FAIL;
|
||||||
}
|
}
|
||||||
need_tabnew = false;
|
|
||||||
if (!wp->w_arg_idx_invalid) {
|
if (!wp->w_arg_idx_invalid) {
|
||||||
edited_win = wp;
|
edited_win = wp;
|
||||||
}
|
}
|
||||||
@@ -652,7 +681,7 @@ static int makeopens(FILE *fd, char_u *dirnow)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// If no file got edited create an empty tab page.
|
// If no file got edited create an empty tab page.
|
||||||
if (need_tabnew && put_line(fd, "tabnew") == FAIL) {
|
if (need_tabnext && put_line(fd, "tabnext") == FAIL) {
|
||||||
return FAIL;
|
return FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -775,6 +804,7 @@ static int makeopens(FILE *fd, char_u *dirnow)
|
|||||||
//
|
//
|
||||||
if (fprintf(fd, "%s",
|
if (fprintf(fd, "%s",
|
||||||
"if exists('s:wipebuf') "
|
"if exists('s:wipebuf') "
|
||||||
|
"&& len(win_findbuf(s:wipebuf)) == 0"
|
||||||
"&& getbufvar(s:wipebuf, '&buftype') isnot# 'terminal'\n"
|
"&& getbufvar(s:wipebuf, '&buftype') isnot# 'terminal'\n"
|
||||||
" silent exe 'bwipe ' . s:wipebuf\n"
|
" silent exe 'bwipe ' . s:wipebuf\n"
|
||||||
"endif\n"
|
"endif\n"
|
||||||
|
@@ -220,6 +220,53 @@ func Test_mksession_one_buffer_two_windows()
|
|||||||
call delete('Xtest_mks.out')
|
call delete('Xtest_mks.out')
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
|
func Test_mksession_lcd_multiple_tabs()
|
||||||
|
tabnew
|
||||||
|
tabnew
|
||||||
|
lcd
|
||||||
|
tabfirst
|
||||||
|
lcd
|
||||||
|
mksession! Xtest_mks.out
|
||||||
|
tabonly
|
||||||
|
source Xtest_mks.out
|
||||||
|
call assert_true(haslocaldir(), 'Tab 1 localdir')
|
||||||
|
tabnext 2
|
||||||
|
call assert_true(!haslocaldir(), 'Tab 2 localdir')
|
||||||
|
tabnext 3
|
||||||
|
call assert_true(haslocaldir(), 'Tab 3 localdir')
|
||||||
|
call delete('Xtest_mks.out')
|
||||||
|
endfunc
|
||||||
|
|
||||||
|
func Test_mksession_blank_tabs()
|
||||||
|
tabnew
|
||||||
|
tabnew
|
||||||
|
tabnew
|
||||||
|
tabnext 3
|
||||||
|
mksession! Xtest_mks.out
|
||||||
|
tabnew
|
||||||
|
tabnew
|
||||||
|
tabnext 2
|
||||||
|
source Xtest_mks.out
|
||||||
|
call assert_equal(4, tabpagenr('$'), 'session restore should restore number of tabs')
|
||||||
|
call assert_equal(3, tabpagenr(), 'session restore should restore the active tab')
|
||||||
|
call delete('Xtest_mks.out')
|
||||||
|
endfunc
|
||||||
|
|
||||||
|
func Test_mksession_blank_windows()
|
||||||
|
split
|
||||||
|
split
|
||||||
|
split
|
||||||
|
3 wincmd w
|
||||||
|
mksession! Xtest_mks.out
|
||||||
|
split
|
||||||
|
split
|
||||||
|
2 wincmd w
|
||||||
|
source Xtest_mks.out
|
||||||
|
call assert_equal(4, winnr('$'), 'session restore should restore number of windows')
|
||||||
|
call assert_equal(3, winnr(), 'session restore should restore the active window')
|
||||||
|
call delete('Xtest_mks.out')
|
||||||
|
endfunc
|
||||||
|
|
||||||
if has('extra_search')
|
if has('extra_search')
|
||||||
|
|
||||||
func Test_mksession_hlsearch()
|
func Test_mksession_hlsearch()
|
||||||
|
Reference in New Issue
Block a user