From 7dccbfed10b32a5cb8d01db88844828a428eeb5a Mon Sep 17 00:00:00 2001 From: Barrett Ruth <62671086+barrettruth@users.noreply.github.com> Date: Thu, 9 Jul 2026 16:47:56 -0500 Subject: [PATCH] fix(dir): select origin on parent navigation #40658 --- runtime/lua/nvim/dir.lua | 6 +++++- test/functional/plugin/dir_spec.lua | 3 +++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/runtime/lua/nvim/dir.lua b/runtime/lua/nvim/dir.lua index 2a36f6cab2..f1d326bf54 100644 --- a/runtime/lua/nvim/dir.lua +++ b/runtime/lua/nvim/dir.lua @@ -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() diff --git a/test/functional/plugin/dir_spec.lua b/test/functional/plugin/dir_spec.lua index f9c96aa0bf..fa4819b066 100644 --- a/test/functional/plugin/dir_spec.lua +++ b/test/functional/plugin/dir_spec.lua @@ -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 })