-
-
Notifications
You must be signed in to change notification settings - Fork 629
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
---@param mode string | ||
---@param node Node | ||
---@param edit_opts NodeEditOpts? | ||
local function edit(mode, node, edit_opts) |
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: just moved this function higher so that I can refer to it from toggle_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.
Moved it up during review and the changes are indeed minimal.
Could we please leave edit where it is, and move Api.tree.toggle_descend_until
below it? That will result in a cleaner git history.
I've made that change on a temporary branch for review https://github.com/nvim-tree/nvim-tree.lua/compare/expand-until-2-alex-refactor?expand=1
Yes, the API is a mess however will be cleaned up in #3088
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
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
-
@@ -72,12 +102,13 @@ local function gen_iterator() | |||
end | |||
|
|||
---@param node Node? | |||
local function expand_node(node) | |||
---@param expand_opts ApiTreeExpandAllOpts? |
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.
---@param expand_opts ApiTreeExpandAllOpts? | |
---@param expand_opts ApiTreeExpandOpts? |
This will bring it into parity with #3133
---@param mode string | ||
---@param node Node | ||
---@param edit_opts NodeEditOpts? | ||
local function edit(mode, node, edit_opts) |
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.
Moved it up during review and the changes are indeed minimal.
Could we please leave edit where it is, and move Api.tree.toggle_descend_until
below it? That will result in a cleaner git history.
I've made that change on a temporary branch for review https://github.com/nvim-tree/nvim-tree.lua/compare/expand-until-2-alex-refactor?expand=1
Yes, the API is a mess however will be cleaned up in #3088
@@ -186,7 +225,25 @@ Api.tree.search_node = wrap(actions.finders.search_node.fn) | |||
---@field keep_buffers boolean|nil default false | |||
|
|||
Api.tree.collapse_all = wrap(actions.tree.modifiers.collapse.all) | |||
|
|||
---@class ApiTreeExpandAllOpts | |||
---@field descend_until (fun(expansion_count: integer, node: Node): boolean)|nil |
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.
---@field descend_until (fun(expansion_count: integer, node: Node): boolean)|nil | |
---@field expand_until (fun(expansion_count: integer, node: Node): boolean)|nil |
That would match the name of the api methods: expand
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
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