0
0
mirror of https://github.com/vim/vim.git synced 2025-09-25 03:54:15 -04:00

patch 8.2.3593: directory is wrong after executing "lcd" with win_execute()

Problem:    Directory is wrong after executing "lcd" with win_execute().
Solution:   Correct the directory when going back to the original window.
            (closes #9132)
This commit is contained in:
Bram Moolenaar
2021-11-14 11:41:31 +00:00
parent 6a950a6007
commit 7f13b24ab6
5 changed files with 58 additions and 30 deletions

View File

@@ -4796,36 +4796,7 @@ win_enter_ext(win_T *wp, int flags)
}
#endif
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];
if (mch_dirname(cwd, MAXPATHL) == OK)
globaldir = vim_strsave(cwd);
}
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)
{
// Window doesn't have a local directory and we are not in the global
// directory: Change to the global directory.
vim_ignored = mch_chdir((char *)globaldir);
VIM_CLEAR(globaldir);
shorten_fnames(TRUE);
}
fix_current_dir();
#ifdef FEAT_JOB_CHANNEL
entering_window(curwin);
@@ -4875,6 +4846,44 @@ win_enter_ext(win_T *wp, int flags)
return did_decrement;
}
/*
* Used after making another window the current one: change directory if
* needed.
*/
void
fix_current_dir(void)
{
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];
if (mch_dirname(cwd, MAXPATHL) == OK)
globaldir = vim_strsave(cwd);
}
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)
{
// Window doesn't have a local directory and we are not in the global
// directory: Change to the global directory.
vim_ignored = mch_chdir((char *)globaldir);
VIM_CLEAR(globaldir);
shorten_fnames(TRUE);
}
}
/*
* Jump to the first open window that contains buffer "buf", if one exists.