diff src/window.c @ 16427:8c3a1bd270bb v8.1.1218

patch 8.1.1218: cannot set a directory for a tab page commit https://github.com/vim/vim/commit/00aa069db8132851a91cfc5ca7f58ef945c75c73 Author: Bram Moolenaar <Bram@vim.org> Date: Sat Apr 27 20:37:57 2019 +0200 patch 8.1.1218: cannot set a directory for a tab page Problem: Cannot set a directory for a tab page. Solution: Add the tab-local directory. (Yegappan Lakshmanan, closes https://github.com/vim/vim/issues/4212)
author Bram Moolenaar <Bram@vim.org>
date Sat, 27 Apr 2019 20:45:05 +0200
parents 840fa633ad64
children 54ffc82f38a8
line wrap: on
line diff
--- a/src/window.c
+++ b/src/window.c
@@ -3625,6 +3625,8 @@ free_tabpage(tabpage_T *tp)
     unref_var_dict(tp->tp_vars);
 #endif
 
+    vim_free(tp->tp_localdir);
+
 #ifdef FEAT_PYTHON
     python_tabpage_free(tp);
 #endif
@@ -3662,6 +3664,8 @@ win_new_tabpage(int after)
     }
     curtab = newtp;
 
+    newtp->tp_localdir = (tp->tp_localdir == NULL)
+				    ? NULL : vim_strsave(tp->tp_localdir);
     /* Create a new empty window. */
     if (win_alloc_firstwin(tp->tp_curwin) == OK)
     {
@@ -3839,6 +3843,9 @@ find_tabpage(int n)
     tabpage_T	*tp;
     int		i = 1;
 
+    if (n == 0)
+	return curtab;
+
     for (tp = first_tabpage; tp != NULL && i != n; tp = tp->tp_next)
 	++i;
     return tp;
@@ -4451,11 +4458,13 @@ win_enter_ext(
 	curwin->w_cursor.coladd = 0;
     changed_line_abv_curs();	/* assume cursor position needs updating */
 
-    if (curwin->w_localdir != NULL)
-    {
-	/* Window has a local directory: Save current directory as global
-	 * directory (unless that was done already) and change to the local
-	 * directory. */
+    if (curwin->w_localdir != NULL || curtab->tp_localdir != NULL)
+    {
+	char_u	*dirname;
+
+	// Window or tab has a local directory: Save current directory as
+	// global directory (unless that was done already) and change to the
+	// local directory.
 	if (globaldir == NULL)
 	{
 	    char_u	cwd[MAXPATHL];
@@ -4463,7 +4472,12 @@ win_enter_ext(
 	    if (mch_dirname(cwd, MAXPATHL) == OK)
 		globaldir = vim_strsave(cwd);
 	}
-	if (mch_chdir((char *)curwin->w_localdir) == 0)
+	if (curwin->w_localdir != NULL)
+	    dirname = curwin->w_localdir;
+	else
+	    dirname = curtab->tp_localdir;
+
+	if (mch_chdir((char *)dirname) == 0)
 	    shorten_fnames(TRUE);
     }
     else if (globaldir != NULL)