From 6b1f5b88f51c342d6be21141ebb814c065792d94 Mon Sep 17 00:00:00 2001 From: uanela Date: Tue, 9 Dec 2025 16:43:37 +0200 Subject: [PATCH] chore: moving root action dir-up to explorer class --- lua/nvim-tree/actions/root/dir-up.lua | 22 ---------------------- lua/nvim-tree/actions/root/init.lua | 1 - lua/nvim-tree/api.lua | 2 +- lua/nvim-tree/explorer/init.lua | 16 ++++++++++++++++ 4 files changed, 17 insertions(+), 24 deletions(-) delete mode 100644 lua/nvim-tree/actions/root/dir-up.lua diff --git a/lua/nvim-tree/actions/root/dir-up.lua b/lua/nvim-tree/actions/root/dir-up.lua deleted file mode 100644 index a8c41c8c6f0..00000000000 --- a/lua/nvim-tree/actions/root/dir-up.lua +++ /dev/null @@ -1,22 +0,0 @@ -local utils = require("nvim-tree.utils") -local core = require("nvim-tree.core") - -local M = {} - ----@param node Node -function M.fn(node) - if not node or node.name == ".." then - require("nvim-tree.actions.root.change-dir").fn("..") - else - local cwd = core.get_cwd() - if cwd == nil then - return - end - - local newdir = vim.fn.fnamemodify(utils.path_remove_trailing(cwd), ":h") - require("nvim-tree.actions.root.change-dir").fn(newdir) - require("nvim-tree.actions.finders.find-file").fn(node.absolute_path) - end -end - -return M diff --git a/lua/nvim-tree/actions/root/init.lua b/lua/nvim-tree/actions/root/init.lua index 1177e2050e1..cb64420d6d4 100644 --- a/lua/nvim-tree/actions/root/init.lua +++ b/lua/nvim-tree/actions/root/init.lua @@ -1,7 +1,6 @@ local M = {} M.change_dir = require("nvim-tree.actions.root.change-dir") -M.dir_up = require("nvim-tree.actions.root.dir-up") function M.setup(opts) M.change_dir.setup(opts) diff --git a/lua/nvim-tree/api.lua b/lua/nvim-tree/api.lua index a1ee507f8af..cd2b33b953f 100644 --- a/lua/nvim-tree/api.lua +++ b/lua/nvim-tree/api.lua @@ -168,7 +168,7 @@ Api.tree.change_root_to_node = wrap_node(function(node) end end) -Api.tree.change_root_to_parent = wrap_node(actions.root.dir_up.fn) +Api.tree.change_root_to_parent = wrap_node(wrap_explorer("dir_up")) Api.tree.get_node_under_cursor = wrap_explorer("get_node_at_cursor") Api.tree.get_nodes = wrap_explorer("get_nodes") diff --git a/lua/nvim-tree/explorer/init.lua b/lua/nvim-tree/explorer/init.lua index afd1b182cee..3e8df0ebd5c 100644 --- a/lua/nvim-tree/explorer/init.lua +++ b/lua/nvim-tree/explorer/init.lua @@ -659,6 +659,22 @@ function Explorer:get_nodes_by_line(line_start) return nodes_by_line end +---@param node Node +function Explorer:dir_up(node) + if not node or node.name == ".." then + require("nvim-tree.actions.root.change-dir").fn("..") + else + local cwd = core.get_cwd() + if cwd == nil then + return + end + + local newdir = vim.fn.fnamemodify(utils.path_remove_trailing(cwd), ":h") + require("nvim-tree.actions.root.change-dir").fn(newdir) + require("nvim-tree.actions.finders.find-file").fn(node.absolute_path) + end +end + ---Api.tree.get_nodes ---@return nvim_tree.api.Node function Explorer:get_nodes()