Skip to content

Commit d0063d5

Browse files
committed
feat(actions): add expand all action
1 parent e482bad commit d0063d5

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

lua/nvim-tree/actions/expand-all.lua

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
local core = require "nvim-tree.core"
2+
local renderer = require "nvim-tree.renderer"
3+
4+
local M = {}
5+
6+
local function expand(node)
7+
node.open = true
8+
if #node.nodes == 0 then
9+
core.get_explorer():expand(node)
10+
end
11+
end
12+
13+
local function iterate(_node)
14+
for _, node in pairs(_node.nodes) do
15+
if node.nodes and not node.open then
16+
expand(node)
17+
end
18+
19+
if node.open then
20+
iterate(node)
21+
end
22+
end
23+
end
24+
25+
function M.fn()
26+
iterate(core.get_explorer())
27+
renderer.draw()
28+
end
29+
30+
return M

lua/nvim-tree/actions/init.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ local M = {
4545
{ key = "q", action = "close" },
4646
{ key = "g?", action = "toggle_help" },
4747
{ key = "W", action = "collapse_all" },
48+
{ key = "E", action = "expand_all" },
4849
{ key = "S", action = "search_node" },
4950
{ key = ".", action = "run_file_command" },
5051
{ key = "<C-k>", action = "toggle_file_info" },
@@ -57,6 +58,7 @@ local keypress_funcs = {
5758
close = view.close,
5859
close_node = require("nvim-tree.actions.movements").parent_node(true),
5960
collapse_all = require("nvim-tree.actions.collapse-all").fn,
61+
expand_all = require("nvim-tree.actions.expand-all").fn,
6062
copy_absolute_path = require("nvim-tree.actions.copy-paste").copy_absolute_path,
6163
copy_name = require("nvim-tree.actions.copy-paste").copy_filename,
6264
copy_path = require("nvim-tree.actions.copy-paste").copy_path,

0 commit comments

Comments
 (0)