feat(dir): set buffer-local CWD #41174

This commit is contained in:
Barrett Ruth
2026-08-06 02:39:53 -05:00
committed by GitHub
parent 54373e2453
commit 8b0f33a1ab
3 changed files with 19 additions and 2 deletions

View File

@@ -45,7 +45,7 @@ end
local function assert_directory(path)
local ffname = path:sub(-1) == '/' and path or path .. '/'
eq(ffname, api.nvim_buf_get_name(0))
eq(path, vim.fs.normalize(fn.bufname('%')))
eq(path, vim.fs.normalize(fn.fnamemodify(fn.bufname('%'), ':p')))
eq('directory', bufopt('filetype'))
eq(true, bufopt('buflisted'))
end
@@ -576,19 +576,24 @@ describe('nvim.dir', function()
it('navigates entries and refreshes the listing', function()
make_fixture()
n.clear({ args = { '--clean' } })
local cwd = fn.getcwd()
edit(root)
assert_directory(root)
eq(vim.uv.fs_realpath(root), vim.uv.fs_realpath(fn.getcwd()))
eq('alpha.txt', fn.findfile('alpha.txt'))
api.nvim_win_set_cursor(0, { line_of('alpha.txt'), 0 })
feed('<CR>')
poke_eventloop()
eq(file, api.nvim_buf_get_name(0))
eq({ 'alpha' }, lines())
eq(cwd, fn.getcwd())
edit(subdir)
assert_directory(subdir)
eq({ '' }, lines())
eq(vim.uv.fs_realpath(subdir), vim.uv.fs_realpath(fn.getcwd()))
feed('-')
poke_eventloop()