fix(dir): preserve alternate buffer #40659

This commit is contained in:
Barrett Ruth
2026-07-09 14:41:09 -05:00
committed by GitHub
parent 8c285c6c33
commit a54a7f6a78
2 changed files with 21 additions and 1 deletions

View File

@@ -85,7 +85,14 @@ local function render(buf, dir)
then
return false
end
api.nvim_buf_set_name(buf, dir)
api.nvim_buf_call(buf, function()
api.nvim_cmd({
cmd = 'file',
args = { dir },
mods = { keepalt = true },
magic = { file = false, bar = false },
}, {})
end)
if not api.nvim_buf_is_valid(buf) then
return false
end

View File

@@ -164,6 +164,19 @@ describe('nvim.dir', function()
eq(false, exec_lua([[return package.loaded['nvim.dir'] ~= nil]]))
end)
it('preserves alternate buffer when opening a parent directory', function()
make_fixture()
n.clear({ args_rm = { '-u', '--cmd' } })
edit(file)
feed('-')
poke_eventloop()
assert_directory(root)
-- Keep the alternate buffer on the file we navigated up from.
eq(file, api.nvim_buf_get_name(fn.bufnr('#')))
end)
it('uses an absolute buffer name for a relative startup directory argument', function()
make_fixture()
local cwd = assert(vim.uv.cwd())