Skip to content

fix: focus visible parent on collapse all #2261

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

Merged
merged 2 commits into from
Jun 12, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions lua/nvim-tree/actions/tree-modifiers/collapse-all.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
local renderer = require "nvim-tree.renderer"
local utils = require "nvim-tree.utils"
local core = require "nvim-tree.core"
local lib = require "nvim-tree.lib"
local Iterator = require "nvim-tree.iterators.node-iterator"

local M = {}
Expand All @@ -22,17 +23,20 @@ local function buf_match()
end

function M.fn(keep_buffers)
if not core.get_explorer() then
local node = lib.get_node_at_cursor()
local explorer = core.get_explorer()

if explorer == nil then
return
end

local matches = buf_match()

Iterator.builder(core.get_explorer().nodes)
Iterator.builder(explorer.nodes)
:hidden()
:applier(function(node)
if node.nodes ~= nil then
node.open = keep_buffers == true and matches(node.absolute_path)
:applier(function(n)
if n.nodes ~= nil then
n.open = keep_buffers == true and matches(n.absolute_path)
end
end)
:recursor(function(n)
Expand All @@ -41,6 +45,7 @@ function M.fn(keep_buffers)
:iterate()

renderer.draw()
utils.focus_node_or_parent(node)
end

return M