-
-
Notifications
You must be signed in to change notification settings - Fork 632
feat: Allow to expand nodes until certain condition is met #3166
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
base: master
Are you sure you want to change the base?
Conversation
lua/nvim-tree/api.lua
Outdated
Api.tree.expand_all = wrap_node(actions.tree.modifiers.expand.all) | ||
|
||
Api.tree.toggle_descend_until = wrap_node(function(node, descend_until) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note: this is actually what I would like to achieve in the end. The fixededit
part is wrong as nodes are not getting collapsed after hitting enter for the second time. Can you advise?
question: how should the end user api look like?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will be very useful, however it needs a bit of thought.
Can we please do this in a future PR? The functionality for the API expands is working and we can merge that now.
What should it look like? This isn't something the user should have to do; it should be core functionality.
It could go into node.open.edit
, as a new member of NodeEditOpts
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doing it in a separate PR makes perfect sense 👍
Thanks for getting back to this one @ghostbuster91 My time is limited, however I will get to reviewing next weekend. FYI the nightly CI failure has been resolved on master: #3167 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good, let's merge the expand functionality now.
Please:
- revert the ordering changes in
api.lua
- rename
ApiTreeExpandOpts
- rename
expand_until
- revert
toggle_descend_until
for a future PR - add :help for
-
api.tree.expand_all
-
api.node.expand
-
lua/nvim-tree/api.lua
Outdated
Api.tree.expand_all = wrap_node(actions.tree.modifiers.expand.all) | ||
|
||
Api.tree.toggle_descend_until = wrap_node(function(node, descend_until) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will be very useful, however it needs a bit of thought.
Can we please do this in a future PR? The functionality for the API expands is working and we can merge that now.
What should it look like? This isn't something the user should have to do; it should be core functionality.
It could go into node.open.edit
, as a new member of NodeEditOpts
All comments have been addressed. Ready for the final review |
end | ||
|
||
if not dir.open and should_descend(expansion_count, node) then | ||
core.get_explorer():expand(dir) -- populate node.group_next |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thought: I need to check but after this change calling that method from the expand
method might be redundant
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're getting really close.
- Expand all does not expand grouped nodes
- expand.lua expects
descend_until
from the user, notexpand_until
- Help needs to document
expand_until
; I'll do that one -
max_folder_discovery
is not obeyed when usingexpand_until
api.tree.expand_all
with no expand_until

api.tree.expand
on node with no expand_until

This doesn't apply:
---@type ApiTreeExpandOpts
local expand_all_opts = {
expand_until = function(i, node)
print(i .. " " .. node.name)
return node.name ~= "stop" and node.name ~= ".git" and node.name ~= "7"
end
}
tree.expand_all({node}, {opts}) *nvim-tree-api.tree.expand_all()*
Recursively expand all nodes under the tree root or specified folder.
Parameters: ~
• {node} (Node|nil) folder
• {opts} (ApiTreeExpandOpts) optional parameters
Options: ~
• {expand_until} ((fun(expansion_count: integer, node: Node?): boolean)?)
Return true if {node} should be expanded.
{expansion_count} is the total number of folders expanded. node.expand({node}, {opts}) *nvim-tree-api.node.expand()*
Recursively expand all nodes under a directory or a file's parent
directory.
Parameters: ~
• {node} (Node|nil) file or folder
• {opts} (ApiTreeExpandOpts) optional parameters
Options: ~
• {expand_until} ((fun(expansion_count: integer, node: Node?): boolean)?)
Return true if {node} should be expanded.
{expansion_count} is the total number of folders expanded. |
This closes #2789
It took me a while but here I am :) I decided to create a fresh one as it was easier then resolving conflicts on the old one.
For now bare minimum of the changes that makes it work. Once we agree how the api will look like I will add docs following what we did in #2790