-
-
Notifications
You must be signed in to change notification settings - Fork 622
feat: allow passing node to collapse all #3133
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
@alex-courtis Please review and lmk if you have any comments. Then I'll update the api docs |
I saw the issue before seeing this PR. Please use an |
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.
Many thanks for the fast PR. Please:
- handle legacy api calls feat: allow passing node to collapse all #3133 (comment)
- use opts - my apologies, I advised you incorrectly Collapse directories under current highlighted directory #3132 (comment)
- Snake case please
node_at_cursor
---@param keep_buffers boolean | ||
function M.fn(keep_buffers) | ||
function M.fn(node, keep_buffers) |
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.
As we are changing the signature of this API, we're going to need to retain backwards compatibility, in the case of the user calling it like collapse_all(true)
See
nvim-tree.lua/lua/nvim-tree/actions/tree/toggle.lua
Lines 7 to 29 in 1ae1c33
---Toggle the tree. | |
---@param opts ApiTreeToggleOpts|nil|boolean legacy -> opts.find_file | |
---@param no_focus string|nil legacy -> opts.focus | |
---@param cwd boolean|nil legacy -> opts.path | |
---@param bang boolean|nil legacy -> opts.update_root | |
function M.fn(opts, no_focus, cwd, bang) | |
-- legacy arguments | |
if type(opts) == "boolean" then | |
opts = { | |
find_file = opts, | |
} | |
if type(cwd) == "string" then | |
opts.path = cwd | |
end | |
if type(no_focus) == "boolean" then | |
opts.focus = not no_focus | |
end | |
if type(bang) == "boolean" then | |
opts.update_root = bang | |
end | |
end | |
opts = opts or {} | |
Test cases: vim.keymap.set("n", "nk", function()
local node = api.tree.get_node_under_cursor()
api.tree.collapse_all(node, true)
end, opts("Collapse Node Keep"))
vim.keymap.set("n", "nn", function()
local node = api.tree.get_node_under_cursor()
api.tree.collapse_all(node, false)
end, opts("Collapse Node No Keep"))
vim.keymap.set("n", "ak", function()
api.tree.collapse_all(nil, true)
end, opts("Collapse All Keep"))
vim.keymap.set("n", "an", function()
api.tree.collapse_all(nil, false)
end, opts("Collapse All No Keep"))
-- collapse-all.lua:43: attempt to index local 'node' (a boolean value)
vim.keymap.set("n", "lk", function()
api.tree.collapse_all(true)
end, opts("Collapse All Legacy Keep"))
-- collapse-all.lua:43: attempt to index local 'node' (a boolean value)
vim.keymap.set("n", "ln", function()
api.tree.collapse_all(true)
end, opts("Collapse All Legacy No Keep")) Following addition of vim.keymap.set("n", "nk", function()
local node = api.tree.get_node_under_cursor()
api.tree.collapse_all(node, { keep_buffers = true, })
end, opts("Collapse Node Keep")) |
Apologies, my time is limited, I'll look at this next weekend. |
Summary
Support passing
node
tocollapse_all
to allow collapsing all dirs under a given node instead of always root node.Addresses #3132 by providing an api