0
0
mirror of https://github.com/vim/vim.git synced 2025-09-05 21:43:39 -04:00

patch 8.2.3468: problem with :cd when editing file in non-existent directory

Problem:    Problem with :cd when editing file in non-existent directory. (Yee
            Cheng Chin)
Solution:   Prepend the current directory to get the full path. (closes #8903)
This commit is contained in:
Bram Moolenaar 2021-10-03 19:29:48 +01:00
parent 5a9357d0bf
commit c6376c7984
3 changed files with 28 additions and 1 deletions

View File

@ -2647,7 +2647,15 @@ mch_FullName(
{ {
vim_strncpy(buf, fname, p - fname); vim_strncpy(buf, fname, p - fname);
if (mch_chdir((char *)buf)) if (mch_chdir((char *)buf))
{
// Path does not exist (yet). For a full path fail,
// will use the path as-is. For a relative path use
// the current directory and append the file name.
if (mch_isFullName(fname))
retval = FAIL; retval = FAIL;
else
p = NULL;
}
else if (*p == '/') else if (*p == '/')
fname = p + 1; fname = p + 1;
else else

View File

@ -208,4 +208,21 @@ func Test_cd_completion()
call delete('XComplFile') call delete('XComplFile')
endfunc endfunc
func Test_cd_unknown_dir()
call mkdir('Xa')
cd Xa
call writefile(['text'], 'Xb.txt')
edit Xa/Xb.txt
let first_buf = bufnr()
cd ..
edit
call assert_equal(first_buf, bufnr())
edit Xa/Xb.txt
call assert_notequal(first_buf, bufnr())
bwipe!
exe "bwipe! " .. first_buf
call delete('Xa', 'rf')
endfunc
" vim: shiftwidth=2 sts=2 expandtab " vim: shiftwidth=2 sts=2 expandtab

View File

@ -757,6 +757,8 @@ static char *(features[]) =
static int included_patches[] = static int included_patches[] =
{ /* Add new patch number below this line */ { /* Add new patch number below this line */
/**/
3468,
/**/ /**/
3467, 3467,
/**/ /**/