Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 0 additions & 22 deletions lua/nvim-tree/actions/root/dir-up.lua

This file was deleted.

1 change: 0 additions & 1 deletion lua/nvim-tree/actions/root/init.lua
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
2 changes: 1 addition & 1 deletion lua/nvim-tree/api.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
16 changes: 16 additions & 0 deletions lua/nvim-tree/explorer/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please move these requires up to the top of the file. Here's an example you can follow: https://github.com/nvim-tree/nvim-tree.lua/blob/master/lua/nvim-tree/actions/tree/open.lua#L3

Why do this at the start of the file?

  • We only want to do it once, for speed
  • Any problems with the require are found immediately at startup, instead of later at runtime

end
end

---Api.tree.get_nodes
---@return nvim_tree.api.Node
function Explorer:get_nodes()
Expand Down
Loading