mirror of
https://github.com/neovim/neovim.git
synced 2026-08-02 13:49:19 +00:00
fix(buffer): name becomes empty when it is the cwd #40980
Problem: Shortening the name of a buffer whose full name is the current directory + path sep yields empty string -> buf unnamed. This doesn't interact well with things like `:mksession`, which for example could `:badd` with no arg -> E471. Solution: Keep the full path when shortening yields an empty name, as `path_try_shorten_fname()` already does.
This commit is contained in:
@@ -2378,11 +2378,10 @@ void shorten_buf_fname(buf_T *buf, char *dirname, int force)
|
||||
XFREE_CLEAR(buf->b_sfname);
|
||||
}
|
||||
char *p = path_shorten_fname(buf->b_ffname, dirname);
|
||||
if (p != NULL) {
|
||||
if (p != NULL && *p != NUL) {
|
||||
buf->b_sfname = xstrdup(p);
|
||||
buf->b_fname = buf->b_sfname;
|
||||
}
|
||||
if (p == NULL) {
|
||||
} else {
|
||||
buf->b_fname = buf->b_ffname;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -188,6 +188,22 @@ describe(':mksession', function()
|
||||
eq(expected, api.nvim_buf_get_name(0))
|
||||
end)
|
||||
|
||||
it('restores a directory buffer for the CWD #40939', function()
|
||||
local cwd_dir = t.fix_slashes(fn.getcwd())
|
||||
local expected = cwd_dir .. '/'
|
||||
|
||||
command('set sessionoptions=buffers,curdir')
|
||||
command('edit ' .. cwd_dir)
|
||||
command('cd ' .. cwd_dir)
|
||||
neq('', fn.bufname('%'))
|
||||
eq(expected, api.nvim_buf_get_name(0))
|
||||
|
||||
command('mksession ' .. session_file)
|
||||
command('%bwipeout!')
|
||||
command('source ' .. session_file)
|
||||
eq(expected, api.nvim_buf_get_name(0))
|
||||
end)
|
||||
|
||||
it('restores CWD for :terminal buffers #11288', function()
|
||||
local cwd_dir = fn.fnamemodify('.', ':p:~'):gsub([[/*$]], '')
|
||||
local session_path = cwd_dir .. '/' .. session_file
|
||||
|
||||
Reference in New Issue
Block a user