aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/nvim/ex_docmd.c21
-rw-r--r--test/functional/ex_cmds/mksession_spec.lua49
2 files changed, 65 insertions, 5 deletions
diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c
index a0406cf418..af8845de87 100644
--- a/src/nvim/ex_docmd.c
+++ b/src/nvim/ex_docmd.c
@@ -8847,15 +8847,16 @@ makeopens (
*/
tab_firstwin = firstwin; /* first window in tab page "tabnr" */
tab_topframe = topframe;
- for (tabnr = 1;; ++tabnr) {
+ for (tabnr = 1;; tabnr++) {
+ tabpage_T *tp = find_tabpage(tabnr);
+ if (tp == NULL) {
+ break; // done all tab pages
+ }
+
int need_tabnew = false;
int cnr = 1;
if ((ssop_flags & SSOP_TABPAGES)) {
- tabpage_T *tp = find_tabpage(tabnr);
-
- if (tp == NULL)
- break; /* done all tab pages */
if (tp == curtab) {
tab_firstwin = firstwin;
tab_topframe = topframe;
@@ -8968,6 +8969,16 @@ makeopens (
if (nr > 1 && ses_winsizes(fd, restore_size, tab_firstwin) == FAIL)
return FAIL;
+ // Take care of tab-local working directories if applicable
+ if (tp->tp_localdir) {
+ if (fputs("if has('nvim') | tcd ", fd) < 0
+ || ses_put_fname(fd, tp->tp_localdir, &ssop_flags) == FAIL
+ || fputs(" | endif", fd) < 0
+ || put_eol(fd) == FAIL) {
+ return FAIL;
+ }
+ }
+
/* Don't continue in another tab page when doing only the current one
* or when at the last tab page. */
if (!(ssop_flags & SSOP_TABPAGES))
diff --git a/test/functional/ex_cmds/mksession_spec.lua b/test/functional/ex_cmds/mksession_spec.lua
new file mode 100644
index 0000000000..5d658f10bb
--- /dev/null
+++ b/test/functional/ex_cmds/mksession_spec.lua
@@ -0,0 +1,49 @@
+local lfs = require('lfs')
+local helpers = require('test.functional.helpers')(after_each)
+
+local clear = helpers.clear
+local command = helpers.command
+local get_pathsep = helpers.get_pathsep
+local eq = helpers.eq
+local funcs = helpers.funcs
+
+local file_prefix = 'Xtest-functional-ex_cmds-mksession_spec'
+
+describe(':mksession', function()
+ local session_file = file_prefix .. '.vim'
+ local tab_dir = file_prefix .. '.d'
+
+ before_each(function()
+ clear()
+ lfs.mkdir(tab_dir)
+ end)
+
+ after_each(function()
+ os.remove(session_file)
+ lfs.rmdir(tab_dir)
+ end)
+
+ it('restores tab-local working directories', function()
+ local tmpfile_base = file_prefix .. '-tmpfile'
+ local cwd_dir = funcs.getcwd()
+
+ -- :mksession does not save empty tabs, so create some buffers.
+ command('edit ' .. tmpfile_base .. '1')
+ command('tabnew')
+ command('edit ' .. tmpfile_base .. '2')
+ command('tcd ' .. tab_dir)
+ command('tabfirst')
+ command('mksession ' .. session_file)
+
+ -- Create a new test instance of Nvim.
+ clear()
+
+ command('source ' .. session_file)
+ -- First tab should have the original working directory.
+ command('tabnext 1')
+ eq(cwd_dir, funcs.getcwd())
+ -- Second tab should have the tab-local working directory.
+ command('tabnext 2')
+ eq(cwd_dir .. get_pathsep() .. tab_dir, funcs.getcwd())
+ end)
+end)