Co-authored-by: Alexander Courtis <alex@courtis.org>
This commit is contained in:
parent
0a99c4a23e
commit
4ee6366ff1
@ -40,17 +40,26 @@ local function wrap(f)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Inject the node as the first argument if absent.
|
---Inject the node as the first argument if absent.
|
||||||
--- f function to invoke
|
---@param fn function function to invoke
|
||||||
local function wrap_node(f)
|
local function wrap_node(fn)
|
||||||
return function(node, ...)
|
return function(node, ...)
|
||||||
node = node or require("nvim-tree.lib").get_node_at_cursor()
|
node = node or require("nvim-tree.lib").get_node_at_cursor()
|
||||||
if node then
|
if node then
|
||||||
f(node, ...)
|
fn(node, ...)
|
||||||
end
|
end
|
||||||
end
|
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
|
---@class ApiTreeOpenOpts
|
||||||
---@field path string|nil path
|
---@field path string|nil path
|
||||||
---@field current_window boolean|nil default false
|
---@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)
|
|||||||
|
|
||||||
Api.tree.is_visible = wrap(require("nvim-tree.view").is_visible)
|
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.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.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")
|
Api.fs.rename_node = wrap_node(require("nvim-tree.actions.fs.rename-file").fn ":t")
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user