Skip to content

Commit 1ef260e

Browse files
authored
feat: add expand_all_subnodes mapping (#1767)
1 parent f1f3306 commit 1ef260e

File tree

8 files changed

+26
-2
lines changed

8 files changed

+26
-2
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,4 @@ tags
4848
luacov.*.out
4949

5050
tests/repro
51+
.repro

.luarc.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626
"ignoreDir": [
2727
".dependencies",
2828
".luarocks",
29-
".lua"
29+
".lua",
30+
".repro"
3031
]
3132
}
3233
}

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,7 @@ return {
316316
-- ['C'] = 'close_all_subnodes',
317317
["z"] = "close_all_nodes",
318318
--["Z"] = "expand_all_nodes",
319+
--["Z"] = "expand_all_subnodes",
319320
["a"] = {
320321
"add",
321322
-- this command supports BASH style brace expansion ("x{a,b,c}" -> xa,xb,xc). see `:h neo-tree-file-actions` for details

doc/neo-tree.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,10 @@ z = close_all_nodes: Close all nodes in the tree.
220220

221221
expand_all_nodes: Expand all directory nodes in the tree recursively.
222222

223+
expand_all_subnodes: Same as expand_all_nodes but defaults to
224+
recursively expanding just the node under the
225+
cursor.
226+
223227
P = toggle_preview: Toggles "preview mode", see |neo-tree-preview-mode|
224228

225229
l = focus_preview: Focus the active preview window

lua/neo-tree/defaults.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,8 +413,10 @@ local config = {
413413
-- ["t"] = "open_tab_drop",
414414
["w"] = "open_with_window_picker",
415415
["C"] = "close_node",
416+
--["C"] = "close_all_subnodes",
416417
["z"] = "close_all_nodes",
417418
--["Z"] = "expand_all_nodes",
419+
--["Z"] = "expand_all_subnodes",
418420
["R"] = "refresh",
419421
["a"] = {
420422
"add",

lua/neo-tree/sources/common/commands.lua

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ end
116116

117117
---Expand all nodes
118118
---@param state table The state of the source
119-
---@param node table A node to expand
119+
---@param node table? A single node to expand (defaults to all root nodes)
120120
---@param prefetcher table? an object with two methods `prefetch(state, node)` and `should_prefetch(node) => boolean`
121121
M.expand_all_nodes = function(state, node, prefetcher)
122122
local root_nodes = node and { node } or state.tree:get_nodes()
@@ -135,6 +135,14 @@ M.expand_all_nodes = function(state, node, prefetcher)
135135
end)
136136
end
137137

138+
---Expand all subnodes
139+
---@param state table The state of the source
140+
---@param node table? A single node to expand (defaults to node under the cursor)
141+
---@param prefetcher table? an object with two methods `prefetch(state, node)` and `should_prefetch(node) => boolean`
142+
M.expand_all_subnodes = function(state, node, prefetcher)
143+
M.expand_all_nodes(state, node or state.tree:get_node(), prefetcher)
144+
end
145+
138146
M.close_node = function(state, callback)
139147
local tree = state.tree
140148
local node = tree:get_node()

lua/neo-tree/sources/filesystem/commands.lua

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ M.expand_all_nodes = function(state, node)
7272
cc.expand_all_nodes(state, node, fs.prefetcher)
7373
end
7474

75+
M.expand_all_subnodes = function(state, node)
76+
cc.expand_all_subnodes(state, node, fs.prefetcher)
77+
end
78+
7579
---Shows the filter input, which will filter the tree.
7680
M.filter_as_you_type = function(state)
7781
filter.show_filter(state, true)

lua/neo-tree/sources/filesystem/init.lua

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,9 @@ end
445445

446446
M.prefetcher = {
447447
prefetch = function(state, node)
448+
if node.type ~= "directory" then
449+
return
450+
end
448451
log.debug("Running fs prefetch for: " .. node:get_id())
449452
fs_scan.get_dir_items_async(state, node:get_id(), true)
450453
end,

0 commit comments

Comments
 (0)