fix(dir): select origin on parent navigation #40658

This commit is contained in:
Barrett Ruth
2026-07-09 16:47:56 -05:00
committed by GitHub
parent de141b4679
commit 7dccbfed10
2 changed files with 8 additions and 1 deletions

View File

@@ -158,7 +158,11 @@ end
---@param buf integer
local function open_parent(buf)
navigate(fs.dirname(api.nvim_buf_get_name(buf)))
local path = api.nvim_buf_get_name(buf)
-- TODO(barrettruth): simplify after #40552
local name = encode_name(fs.basename(path)) .. (vim.fn.isdirectory(path) == 1 and '/' or '')
navigate(fs.dirname(path))
vim.fn.search([[\C\m^\V]] .. vim.fn.escape(name, [[\]]) .. [[\m$]], 'cw')
end
function M._open_entry()

View File

@@ -155,6 +155,9 @@ describe('nvim.dir', function()
assert_directory(root)
line_of('alpha.txt')
-- Ensure the cursor stays on the entry we navigated up from.
eq('alpha.txt', api.nvim_get_current_line())
n.clear({ args_rm = { '--cmd' }, args = { '--noplugin' } })
api.nvim_buf_set_lines(0, 0, -1, false, { ' alpha', ' beta' })
api.nvim_win_set_cursor(0, { 2, 7 })