Compare commits
4 Commits
master
...
expand-unt
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
06079a591d | ||
|
|
114fde0e07 | ||
|
|
641f125f6b | ||
|
|
c1948cbce0 |
@ -30,17 +30,35 @@ end
|
|||||||
---@param expansion_count integer
|
---@param expansion_count integer
|
||||||
---@param node Node
|
---@param node Node
|
||||||
---@return boolean
|
---@return boolean
|
||||||
local function should_expand(expansion_count, node)
|
local function descend_until_max_or_empty(expansion_count, node)
|
||||||
local dir = node:as(DirectoryNode)
|
local dir = node:as(DirectoryNode)
|
||||||
if not dir then
|
if not dir then
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
local should_halt = expansion_count >= M.MAX_FOLDER_DISCOVERY
|
local should_halt = expansion_count >= M.MAX_FOLDER_DISCOVERY
|
||||||
local should_exclude = M.EXCLUDE[dir.name]
|
local should_exclude = M.EXCLUDE[dir.name]
|
||||||
return not should_halt and not dir.open and not should_exclude
|
|
||||||
|
return not should_halt and not should_exclude
|
||||||
end
|
end
|
||||||
|
|
||||||
local function gen_iterator()
|
---@param expansion_count integer
|
||||||
|
---@param node Node
|
||||||
|
---@param should_descend fun(expansion_count: integer, node: Node): boolean
|
||||||
|
---@return boolean
|
||||||
|
local function should_expand(expansion_count, node, should_descend)
|
||||||
|
local dir = node:as(DirectoryNode)
|
||||||
|
if not dir then
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
return not dir.open and should_descend(expansion_count, node)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
---@param should_descend fun(expansion_count: integer, node: Node): boolean
|
||||||
|
---@return fun(node): any
|
||||||
|
local function gen_iterator(should_descend)
|
||||||
local expansion_count = 0
|
local expansion_count = 0
|
||||||
|
|
||||||
return function(parent)
|
return function(parent)
|
||||||
@ -52,7 +70,7 @@ local function gen_iterator()
|
|||||||
Iterator.builder(parent.nodes)
|
Iterator.builder(parent.nodes)
|
||||||
:hidden()
|
:hidden()
|
||||||
:applier(function(node)
|
:applier(function(node)
|
||||||
if should_expand(expansion_count, node) then
|
if should_expand(expansion_count, node, should_descend) then
|
||||||
expansion_count = expansion_count + 1
|
expansion_count = expansion_count + 1
|
||||||
node = node:as(DirectoryNode)
|
node = node:as(DirectoryNode)
|
||||||
if node then
|
if node then
|
||||||
@ -61,7 +79,19 @@ local function gen_iterator()
|
|||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
:recursor(function(node)
|
:recursor(function(node)
|
||||||
return expansion_count < M.MAX_FOLDER_DISCOVERY and (node.group_next and { node.group_next } or (node.open and node.nodes))
|
if not should_descend(expansion_count, node) then
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
|
||||||
|
if node.group_next then
|
||||||
|
return { node.group_next }
|
||||||
|
end
|
||||||
|
|
||||||
|
if node.open and node.nodes then
|
||||||
|
return node.nodes
|
||||||
|
end
|
||||||
|
|
||||||
|
return nil
|
||||||
end)
|
end)
|
||||||
:iterate()
|
:iterate()
|
||||||
|
|
||||||
@ -72,12 +102,13 @@ local function gen_iterator()
|
|||||||
end
|
end
|
||||||
|
|
||||||
---@param node Node?
|
---@param node Node?
|
||||||
local function expand_node(node)
|
---@param expand_opts ApiTreeExpandAllOpts?
|
||||||
|
local function expand_node(node, expand_opts)
|
||||||
if not node then
|
if not node then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
local descend_until = (expand_opts and expand_opts.descend_until) or descend_until_max_or_empty
|
||||||
if gen_iterator()(node) then
|
if gen_iterator(descend_until)(node) then
|
||||||
notify.warn("expansion iteration was halted after " .. M.MAX_FOLDER_DISCOVERY .. " discovered folders")
|
notify.warn("expansion iteration was halted after " .. M.MAX_FOLDER_DISCOVERY .. " discovered folders")
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -89,18 +120,20 @@ end
|
|||||||
|
|
||||||
---Expand the directory node or the root
|
---Expand the directory node or the root
|
||||||
---@param node Node
|
---@param node Node
|
||||||
function M.all(node)
|
---@param expand_opts ApiTreeExpandAllOpts?
|
||||||
expand_node(node and node:as(DirectoryNode) or core.get_explorer())
|
function M.all(node, expand_opts)
|
||||||
|
expand_node(node and node:as(DirectoryNode) or core.get_explorer(), expand_opts)
|
||||||
end
|
end
|
||||||
|
|
||||||
---Expand the directory node or parent node
|
---Expand the directory node or parent node
|
||||||
---@param node Node
|
---@param node Node
|
||||||
function M.node(node)
|
---@param expand_opts ApiTreeExpandAllOpts?
|
||||||
|
function M.node(node, expand_opts)
|
||||||
if not node then
|
if not node then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
expand_node(node:is(FileNode) and node.parent or node:as(DirectoryNode))
|
expand_node(node:is(FileNode) and node.parent or node:as(DirectoryNode), expand_opts)
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.setup(opts)
|
function M.setup(opts)
|
||||||
|
|||||||
@ -186,6 +186,10 @@ Api.tree.search_node = wrap(actions.finders.search_node.fn)
|
|||||||
---@field keep_buffers boolean|nil default false
|
---@field keep_buffers boolean|nil default false
|
||||||
|
|
||||||
Api.tree.collapse_all = wrap(actions.tree.modifiers.collapse.all)
|
Api.tree.collapse_all = wrap(actions.tree.modifiers.collapse.all)
|
||||||
|
|
||||||
|
---@class ApiTreeExpandAllOpts
|
||||||
|
---@field descend_until (fun(expansion_count: integer, node: Node): boolean)|nil
|
||||||
|
|
||||||
Api.tree.expand_all = wrap_node(actions.tree.modifiers.expand.all)
|
Api.tree.expand_all = wrap_node(actions.tree.modifiers.expand.all)
|
||||||
Api.tree.toggle_enable_filters = wrap_explorer_member("filters", "toggle")
|
Api.tree.toggle_enable_filters = wrap_explorer_member("filters", "toggle")
|
||||||
Api.tree.toggle_gitignore_filter = wrap_explorer_member_args("filters", "toggle", "git_ignored")
|
Api.tree.toggle_gitignore_filter = wrap_explorer_member_args("filters", "toggle", "git_ignored")
|
||||||
@ -264,6 +268,19 @@ local function edit(mode, node, edit_opts)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Api.tree.toggle_descend_until = wrap_node(function(node, descend_until)
|
||||||
|
local dir = node:as(DirectoryNode)
|
||||||
|
if dir then
|
||||||
|
if node.open then
|
||||||
|
dir:expand_or_collapse(nil)
|
||||||
|
else
|
||||||
|
actions.tree.modifiers.expand.all(node, { descend_until = descend_until })
|
||||||
|
end
|
||||||
|
else
|
||||||
|
edit("edit", node)
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
---@param mode string
|
---@param mode string
|
||||||
---@param toggle_group boolean?
|
---@param toggle_group boolean?
|
||||||
---@return fun(node: Node, edit_opts: NodeEditOpts?)
|
---@return fun(node: Node, edit_opts: NodeEditOpts?)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user