Skip to content

fix: file creation in empty folder without root_folder_label #2514

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
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
19 changes: 14 additions & 5 deletions lua/nvim-tree/api.lua
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,26 @@ local function wrap(f)
end
end

--- Inject the node as the first argument if absent.
--- f function to invoke
local function wrap_node(f)
---Inject the node as the first argument if absent.
---@param fn function function to invoke
Copy link
Member

Choose a reason for hiding this comment

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

Thank you.

local function wrap_node(fn)
return function(node, ...)
node = node or require("nvim-tree.lib").get_node_at_cursor()
if node then
f(node, ...)
fn(node, ...)
end
end
end

---Inject the node or nil as the first argument if absent.
---@param fn function function to invoke
local function wrap_node_or_nil(fn)
return function(node, ...)
node = node or require("nvim-tree.lib").get_node_at_cursor()
fn(node, ...)
end
end

---@class ApiTreeOpenOpts
---@field path string|nil path
---@field current_window boolean|nil default false
Expand Down Expand Up @@ -136,7 +145,7 @@ Api.tree.is_tree_buf = wrap(require("nvim-tree.utils").is_nvim_tree_buf)

Api.tree.is_visible = wrap(require("nvim-tree.view").is_visible)

Api.fs.create = wrap_node(require("nvim-tree.actions.fs.create-file").fn)
Api.fs.create = wrap_node_or_nil(require("nvim-tree.actions.fs.create-file").fn)
Api.fs.remove = wrap_node(require("nvim-tree.actions.fs.remove-file").fn)
Api.fs.trash = wrap_node(require("nvim-tree.actions.fs.trash").fn)
Api.fs.rename_node = wrap_node(require("nvim-tree.actions.fs.rename-file").fn ":t")
Expand Down