diff options
-rw-r--r-- | src/nvim/ex_docmd.c | 27 | ||||
-rw-r--r-- | test/functional/ex_cmds/mksession_spec.lua | 19 |
2 files changed, 46 insertions, 0 deletions
diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c index 02bee838d5..0732409666 100644 --- a/src/nvim/ex_docmd.c +++ b/src/nvim/ex_docmd.c @@ -9346,6 +9346,10 @@ makeopens( /* * Restore the view of the window (options, file, cursor, etc.). */ + if (put_line(fd, "let s:buffer_names = []") == FAIL) { + return FAIL; + } + for (wp = tab_firstwin; wp != NULL; wp = wp->w_next) { if (!ses_do_win(wp)) continue; @@ -9357,6 +9361,16 @@ makeopens( next_arg_idx = wp->w_arg_idx; } + if (put_line(fd, "for [s:name, s:tbuf] in s:buffer_names") == FAIL + || put_line(fd, " if buflisted(s:tbuf)") == FAIL + || put_line(fd, " execute 'buffer' fnameescape(s:tbuf)") == FAIL + || put_line(fd, " execute 'file' fnameescape(s:name)") == FAIL + || put_line(fd, " endif") == FAIL + || put_line(fd, "endfor") == FAIL + || put_line(fd, "unlet! s:buffer_names s:tbuf s:name") == FAIL) { + return FAIL; + } + /* The argument index in the first tab page is zero, need to set it in * each window. For further tab pages it's the window where we do * "tabedit". */ @@ -9662,6 +9676,19 @@ put_view( || put_eol(fd) == FAIL) { return FAIL; } + + if (fputs("call add(s:buffer_names, [bufname('%'),'", fd) < 0 + || ses_fname(fd, wp->w_buffer, flagp, false) == FAIL + || fputs("'])", fd) < 0 + || put_eol(fd) == FAIL) { + return FAIL; + } + + if (fputs("file ", fd) < 0 + || ses_fname(fd, wp->w_buffer, flagp, false) == FAIL + || put_eol(fd) == FAIL) { + return FAIL; + } } else { // No file in this buffer, just make it empty. if (put_line(fd, "enew") == FAIL) { diff --git a/test/functional/ex_cmds/mksession_spec.lua b/test/functional/ex_cmds/mksession_spec.lua index 855f8105aa..726cfe7fe5 100644 --- a/test/functional/ex_cmds/mksession_spec.lua +++ b/test/functional/ex_cmds/mksession_spec.lua @@ -91,4 +91,23 @@ describe(':mksession', function() matches('^term://'..pesc(expected_cwd)..'//%d+:', funcs.expand('%')) command('qall!') end) + + it('restores multiple windows with same terminal instances', function() + -- Create a view with two buffers referencing the same terminal instance + command('terminal') + command('split') + command('mksession ' .. session_file) + + clear() + + command('source ' .. session_file) + -- Getting the name of the buffer shown to compare with the other window + local eval = helpers.eval + + command('exe 1 . "wincmd w"') + local expected_pid = eval('b:terminal_job_pid') + + command('exe 2 . "wincmd w"') + eq(expected_pid, eval('b:terminal_job_pid')) + end) end) |