-
-
Notifications
You must be signed in to change notification settings - Fork 611
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
feat: support collapse a single folder under cursor #2847
base: master
Are you sure you want to change the base?
Conversation
There might be some imperfections in the naming, documentation, and code details. What I am presenting here is just a rough idea. If this pull request idea is accepted, I will continue to work hard to make more reasonable, reliable, and complete revisions. |
I think I migh not understand what you mean. |
@evertonse No, that is not the same. |
Ah I see now, then there should be |
I update my commit, including the command, doc and explanation. Please review. |
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.
Apologies for not seeing this one earlier...
This is great, we should have had this long ago. I'm thinking about a free default keybinding we can use.
We will do this this however:
- It's missing the
keep_buffers
parameter ofcollapse_all
collapse.lua
repeatscollapse-all.lua
taking a node instead of usingexplorer
Please an optional node parameter to collapse-all.fn
so that it may perform both and keep buffers.
doc/nvim-tree-lua.txt
Outdated
@@ -1770,6 +1778,9 @@ tree.collapse_all({keep_buffers}) *nvim-tree-api.tree.collapse_all()* | |||
Parameters: ~ | |||
• {keep_buffers} (boolean) do not collapse nodes with open buffers. | |||
|
|||
tree.collapse() *nvim-tree-api.tree.collapse()* |
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.
tree.collapse() *nvim-tree-api.tree.collapse()* | |
tree.collapse() *nvim-tree-api.tree.collapse()* |
spacing
This is great, many thanks for pushing this one. |
All right, I've added and option to |
On
It looks like we're changing API from a boolean to an opts table. We'll need to provide backwards compatibility for legacy arguments, similar to Alternative: add an API method TL;DR point 2 was asking to use a single collapse function rather than a single API. |
tree.collapse_all({keep_buffers}) *nvim-tree-api.tree.collapse_all()*
Collapse the entire tree.
Parameters: ~
• {keep_buffers} (boolean) do not collapse nodes with open buffers.
tree.collapse({opts}) *nvim-tree-api.tree.collapse()*
Collapse the tree.
Parameters: ~
• {opts} (table) optional parameters
Options: ~
• {under_cursor} (boolean) only collapse the node under cursor,
default false
• {keep_buffers} (boolean) do not collapse nodes with open buffers,
default false This preserves backward compatibility and the API can stay pure, something like: Api.tree.collapse = wrap(actions.tree.modifiers.collapse_all.collapse)
Api.tree.collapse_all = wrap(actions.tree.modifiers.collapse_all.collapse_all)
---@param keep_buffers boolean
function M.fn(keep_buffers)
M.collapse({keep_buffers = keep_buffers, under_cursor = false})
end Finally, rename |
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, we are close...
When I use
api.tree.expand_all
to expand a folder, sometimes I need to collapse a single folder rather than all folders(invoke byapi.tree.collapse_all
). This feature(api.tree.collapse
) can be understood as the inverse operation ofapi.tree.expand_all
.