Skip to content

Commit 4ee6366

Browse files
fix(#2512): file creation in empty folder without root_folder_label (#2514)
Co-authored-by: Alexander Courtis <alex@courtis.org>
1 parent 0a99c4a commit 4ee6366

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

lua/nvim-tree/api.lua

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,26 @@ local function wrap(f)
4040
end
4141
end
4242

43-
--- Inject the node as the first argument if absent.
44-
--- f function to invoke
45-
local function wrap_node(f)
43+
---Inject the node as the first argument if absent.
44+
---@param fn function function to invoke
45+
local function wrap_node(fn)
4646
return function(node, ...)
4747
node = node or require("nvim-tree.lib").get_node_at_cursor()
4848
if node then
49-
f(node, ...)
49+
fn(node, ...)
5050
end
5151
end
5252
end
5353

54+
---Inject the node or nil as the first argument if absent.
55+
---@param fn function function to invoke
56+
local function wrap_node_or_nil(fn)
57+
return function(node, ...)
58+
node = node or require("nvim-tree.lib").get_node_at_cursor()
59+
fn(node, ...)
60+
end
61+
end
62+
5463
---@class ApiTreeOpenOpts
5564
---@field path string|nil path
5665
---@field current_window boolean|nil default false
@@ -136,7 +145,7 @@ Api.tree.is_tree_buf = wrap(require("nvim-tree.utils").is_nvim_tree_buf)
136145

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

139-
Api.fs.create = wrap_node(require("nvim-tree.actions.fs.create-file").fn)
148+
Api.fs.create = wrap_node_or_nil(require("nvim-tree.actions.fs.create-file").fn)
140149
Api.fs.remove = wrap_node(require("nvim-tree.actions.fs.remove-file").fn)
141150
Api.fs.trash = wrap_node(require("nvim-tree.actions.fs.trash").fn)
142151
Api.fs.rename_node = wrap_node(require("nvim-tree.actions.fs.rename-file").fn ":t")

0 commit comments

Comments
 (0)