* add todo * refactor(#2886): multi instance: node class refactoring: extract links, *_git_status (#2944) * extract DirectoryLinkNode and FileLinkNode, move Node methods to children * temporarily move DirectoryNode methods into BaseNode for easier reviewing * move mostly unchanged DirectoryNode methods back to BaseNode * tidy * git.git_status_file takes an array * update git status of links * luacheck hack * safer git_status_dir * refactor(#2886): multi instance: node class refactoring: DirectoryNode:expand_or_collapse (#2957) move expand_or_collapse to DirectoryNode * refactor(#2886): multi instance: node group functions refactoring (#2959) * move last_group_node to DirectoryNode * move add BaseNode:as and more doc * revert parameter name changes * revert parameter name changes * add Class * move group methods into DN * tidy group methods * tidy group methods * tidy group methods * tidy group methods * parent is DirectoryNode * tidy expand all * BaseNode -> Node * move watcher to DirectoryNode * last_group_node is DirectoryNode only * simplify create-file * simplify parent * simplify collapse-all * simplify live-filter * style * move lib.get_cursor_position to Explorer * move lib.get_node_at_cursor to Explorer * move lib.get_nodes to Explorer * move place_cursor_on_node to Explorer * resolve resource leak in purge_all_state * move many autocommands into Explorer * post merge tidy
This commit is contained in:
committed by
GitHub
parent
8760d76c1d
commit
f3efc25e56
@@ -1,4 +1,3 @@
|
||||
local lib = require("nvim-tree.lib")
|
||||
local core = require("nvim-tree.core")
|
||||
local view = require("nvim-tree.view")
|
||||
local utils = require("nvim-tree.utils")
|
||||
@@ -41,7 +40,7 @@ local Api = {
|
||||
diagnostics = {},
|
||||
}
|
||||
|
||||
--- Print error when setup not called.
|
||||
---Print error when setup not called.
|
||||
---@param fn fun(...): any
|
||||
---@return fun(...): any
|
||||
local function wrap(fn)
|
||||
@@ -54,28 +53,6 @@ local function wrap(fn)
|
||||
end
|
||||
end
|
||||
|
||||
---Inject the node as the first argument if present otherwise do nothing.
|
||||
---@param fn fun(node: Node, ...): any
|
||||
---@return fun(node: Node, ...): any
|
||||
local function wrap_node(fn)
|
||||
return function(node, ...)
|
||||
node = node or lib.get_node_at_cursor()
|
||||
if node then
|
||||
return fn(node, ...)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
---Inject the node or nil as the first argument if absent.
|
||||
---@param fn fun(node: Node, ...): any
|
||||
---@return fun(node: Node, ...): any
|
||||
local function wrap_node_or_nil(fn)
|
||||
return function(node, ...)
|
||||
node = node or lib.get_node_at_cursor()
|
||||
return fn(node, ...)
|
||||
end
|
||||
end
|
||||
|
||||
---Invoke a method on the singleton explorer.
|
||||
---Print error when setup not called.
|
||||
---@param explorer_method string explorer method name
|
||||
@@ -89,6 +66,28 @@ local function wrap_explorer(explorer_method)
|
||||
end)
|
||||
end
|
||||
|
||||
---Inject the node as the first argument if present otherwise do nothing.
|
||||
---@param fn fun(node: Node, ...): any
|
||||
---@return fun(node: Node, ...): any
|
||||
local function wrap_node(fn)
|
||||
return function(node, ...)
|
||||
node = node or wrap_explorer("get_node_at_cursor")()
|
||||
if node then
|
||||
return fn(node, ...)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
---Inject the node or nil as the first argument if absent.
|
||||
---@param fn fun(node: Node, ...): any
|
||||
---@return fun(node: Node, ...): any
|
||||
local function wrap_node_or_nil(fn)
|
||||
return function(node, ...)
|
||||
node = node or wrap_explorer("get_node_at_cursor")()
|
||||
return fn(node, ...)
|
||||
end
|
||||
end
|
||||
|
||||
---Invoke a member's method on the singleton explorer.
|
||||
---Print error when setup not called.
|
||||
---@param explorer_member string explorer member name
|
||||
@@ -147,8 +146,8 @@ Api.tree.change_root_to_node = wrap_node(function(node)
|
||||
end)
|
||||
|
||||
Api.tree.change_root_to_parent = wrap_node(actions.root.dir_up.fn)
|
||||
Api.tree.get_node_under_cursor = wrap(lib.get_node_at_cursor)
|
||||
Api.tree.get_nodes = wrap(lib.get_nodes)
|
||||
Api.tree.get_node_under_cursor = wrap_explorer("get_node_at_cursor")
|
||||
Api.tree.get_nodes = wrap_explorer("get_nodes")
|
||||
|
||||
---@class ApiTreeFindFileOpts
|
||||
---@field buf string|number|nil
|
||||
|
||||
Reference in New Issue
Block a user