Skip to content

Commit b63d367

Browse files
Uanelaalex-courtis
andauthored
refactor(#2988): multi instance dir_up (#3222)
* chore: moving root action dir-up to explorer class * chore(explorer): moving requires to top level --------- Co-authored-by: Alexander Courtis <[email protected]>
1 parent 8298117 commit b63d367

File tree

4 files changed

+19
-24
lines changed

4 files changed

+19
-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: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ local Clipboard = require("nvim-tree.actions.fs.clipboard")
2222
local Renderer = require("nvim-tree.renderer")
2323

2424
local FILTER_REASON = require("nvim-tree.enum").FILTER_REASON
25+
local change_dir = require("nvim-tree.actions.root.change-dir")
26+
local find_file = require("nvim-tree.actions.finders.find-file")
2527

2628
local config
2729

@@ -659,6 +661,22 @@ function Explorer:get_nodes_by_line(line_start)
659661
return nodes_by_line
660662
end
661663

664+
---@param node Node
665+
function Explorer:dir_up(node)
666+
if not node or node.name == ".." then
667+
change_dir.fn("..")
668+
else
669+
local cwd = core.get_cwd()
670+
if cwd == nil then
671+
return
672+
end
673+
674+
local newdir = vim.fn.fnamemodify(utils.path_remove_trailing(cwd), ":h")
675+
change_dir.fn(newdir)
676+
find_file.fn(node.absolute_path)
677+
end
678+
end
679+
662680
---Api.tree.get_nodes
663681
---@return nvim_tree.api.Node
664682
function Explorer:get_nodes()

0 commit comments

Comments
 (0)