Skip to content
Merged
16 changes: 12 additions & 4 deletions lua/nvim-tree/api.lua
Original file line number Diff line number Diff line change
Expand Up @@ -222,21 +222,29 @@ Api.fs.copy.absolute_path = wrap_node(wrap_explorer_member("clipboard", "copy_ab
Api.fs.copy.filename = wrap_node(wrap_explorer_member("clipboard", "copy_filename"))
Api.fs.copy.basename = wrap_node(wrap_explorer_member("clipboard", "copy_basename"))
Api.fs.copy.relative_path = wrap_node(wrap_explorer_member("clipboard", "copy_path"))
---
---@class NodeEditOpts
---@field quit_on_open boolean|nil default false

---@param mode string
---@param node Node
local function edit(mode, node)
---@param edit_opts NodeEditOpts?
local function edit(mode, node, edit_opts)
local file_link = node:as(FileLinkNode)
local path = file_link and file_link.link_to or node.absolute_path
actions.node.open_file.fn(mode, path)

if edit_opts and edit_opts.quit_on_open then
view.close()
end
end

---@param mode string
---@param toggle_group boolean?
---@return fun(node: Node)
---@return fun(node: Node, edit_opts: NodeEditOpts?)
local function open_or_expand_or_dir_up(mode, toggle_group)
---@param node Node
Copy link
Member

Choose a reason for hiding this comment

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

Missing param, CI got upset: https://github.com/nvim-tree/nvim-tree.lua/actions/runs/12975816599/job/36187330634?pr=3054

Needs

  ---@param edit_opts NodeEditOpts?

I recommend setting up wiki: Lua Language Server, which will show a warning about these sorts of things.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ok will do, thanks :)

return function(node)
return function(node, edit_opts)
local root = node:as(RootNode)
local dir = node:as(DirectoryNode)

Expand All @@ -245,7 +253,7 @@ local function open_or_expand_or_dir_up(mode, toggle_group)
elseif dir then
dir:expand_or_collapse(toggle_group)
elseif not toggle_group then
edit(mode, node)
edit(mode, node, edit_opts)
end
end
end
Expand Down
Loading