From df94463e764906803e5a14a3df6f249dccece767 Mon Sep 17 00:00:00 2001 From: Alexander Courtis Date: Mon, 8 Sep 2025 16:18:09 +1000 Subject: [PATCH] refactor(#2942): multi instance: remove unnecessary focus_file --- lua/nvim-tree/actions/moves/sibling.lua | 2 +- lua/nvim-tree/explorer/init.lua | 10 +--------- lua/nvim-tree/explorer/live-filter.lua | 4 ++-- lua/nvim-tree/marks/init.lua | 2 +- 4 files changed, 5 insertions(+), 13 deletions(-) diff --git a/lua/nvim-tree/actions/moves/sibling.lua b/lua/nvim-tree/actions/moves/sibling.lua index 24347db4..bfb5b5e2 100644 --- a/lua/nvim-tree/actions/moves/sibling.lua +++ b/lua/nvim-tree/actions/moves/sibling.lua @@ -49,7 +49,7 @@ function M.fn(direction) end if target_node then - explorer:focus_file(target_node.absolute_path) + explorer:focus_node_or_parent(target_node) end end end diff --git a/lua/nvim-tree/explorer/init.lua b/lua/nvim-tree/explorer/init.lua index db1961a8..58f58b03 100644 --- a/lua/nvim-tree/explorer/init.lua +++ b/lua/nvim-tree/explorer/init.lua @@ -599,14 +599,6 @@ function Explorer:get_node_from_path(path) :iterate() end ----@param path string -function Explorer:focus_file(path) - local _, i = self:find_node(function(node) - return node.absolute_path == path - end) - view.set_cursor({ i + 1, 1 }) -end - ---Focus node passed as parameter if visible, otherwise focus first visible parent. ---If none of the parents is visible focus root. ---If node is nil do nothing. @@ -619,7 +611,7 @@ function Explorer:focus_node_or_parent(node) end) if found_node or node.parent == nil then - require("nvim-tree.view").set_cursor({ i + 1, 1 }) + view.set_cursor({ i + 1, 1 }) break end diff --git a/lua/nvim-tree/explorer/live-filter.lua b/lua/nvim-tree/explorer/live-filter.lua index df557737..43e68316 100644 --- a/lua/nvim-tree/explorer/live-filter.lua +++ b/lua/nvim-tree/explorer/live-filter.lua @@ -220,9 +220,9 @@ function LiveFilter:clear_filter() self.explorer.renderer:draw() if node then - self.explorer:focus_file(node.absolute_path) + self.explorer:focus_node_or_parent(node) elseif last_node then - self.explorer:focus_file(last_node.absolute_path) + self.explorer:focus_node_or_parent(last_node) end end diff --git a/lua/nvim-tree/marks/init.lua b/lua/nvim-tree/marks/init.lua index 5fb3e920..22ac572d 100644 --- a/lua/nvim-tree/marks/init.lua +++ b/lua/nvim-tree/marks/init.lua @@ -263,7 +263,7 @@ function Marks:navigate_select() if node and not node:is(DirectoryNode) and not utils.get_win_buf_from_path(node.absolute_path) then open_file.fn("edit", node.absolute_path) elseif node then - self.explorer:focus_file(node.absolute_path) + self.explorer:focus_node_or_parent(node) end end) end