Skip to content

Commit 6b1f5b8

Browse files
committed
chore: moving root action dir-up to explorer class
1 parent eb33612 commit 6b1f5b8

File tree

4 files changed

+17
-24
lines changed

4 files changed

+17
-24
lines changed

lua/nvim-tree/actions/root/dir-up.lua

Lines changed: 0 additions & 22 deletions
This file was deleted.

lua/nvim-tree/actions/root/init.lua

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
local M = {}
22

33
M.change_dir = require("nvim-tree.actions.root.change-dir")
4-
M.dir_up = require("nvim-tree.actions.root.dir-up")
54

65
function M.setup(opts)
76
M.change_dir.setup(opts)

lua/nvim-tree/api.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ Api.tree.change_root_to_node = wrap_node(function(node)
168168
end
169169
end)
170170

171-
Api.tree.change_root_to_parent = wrap_node(actions.root.dir_up.fn)
171+
Api.tree.change_root_to_parent = wrap_node(wrap_explorer("dir_up"))
172172
Api.tree.get_node_under_cursor = wrap_explorer("get_node_at_cursor")
173173
Api.tree.get_nodes = wrap_explorer("get_nodes")
174174

lua/nvim-tree/explorer/init.lua

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -659,6 +659,22 @@ function Explorer:get_nodes_by_line(line_start)
659659
return nodes_by_line
660660
end
661661

662+
---@param node Node
663+
function Explorer:dir_up(node)
664+
if not node or node.name == ".." then
665+
require("nvim-tree.actions.root.change-dir").fn("..")
666+
else
667+
local cwd = core.get_cwd()
668+
if cwd == nil then
669+
return
670+
end
671+
672+
local newdir = vim.fn.fnamemodify(utils.path_remove_trailing(cwd), ":h")
673+
require("nvim-tree.actions.root.change-dir").fn(newdir)
674+
require("nvim-tree.actions.finders.find-file").fn(node.absolute_path)
675+
end
676+
end
677+
662678
---Api.tree.get_nodes
663679
---@return nvim_tree.api.Node
664680
function Explorer:get_nodes()

0 commit comments

Comments
 (0)