fix(dir): "-" on a non-file buffer opens a bogus path #41034

This commit is contained in:
Barrett Ruth 2026-07-28 12:37:06 -05:00 committed by GitHub
parent 4bba83b4b7
commit 0d36e61d70
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 10 additions and 2 deletions

View File

@ -47,7 +47,7 @@ end
---@param path string
function M.open_parent_path(path)
if path == '' then
if path == '' or path:find('^%a[%w+.-]*://') then
navigate('.')
return
end

View File

@ -376,15 +376,23 @@ describe('nvim.dir', function()
eq(vim.fs.basename(root) .. '/', api.nvim_get_current_line())
end)
it('maps - to open the current directory from an unnamed buffer', function()
it('maps - to open the current directory from a buffer with no path', function()
make_fixture()
n.clear({ args_rm = { '--cmd' }, args = { '--clean' } })
local cwd = fn.getcwd()
command('terminal')
eq('terminal', api.nvim_get_option_value('buftype', { buf = 0 }))
cd(root)
finally(function()
cd(cwd)
end)
feed('-')
poke_eventloop()
assert_directory(root)
command('enew')
eq('', api.nvim_buf_get_name(0))
feed('-')
poke_eventloop()