File tree 3 files changed +41
-0
lines changed
3 files changed +41
-0
lines changed Original file line number Diff line number Diff line change @@ -1147,6 +1147,7 @@ exists.
1147
1147
- change_root_to_node
1148
1148
- change_root_to_parent
1149
1149
- get_node_under_cursor
1150
+ - get_nodes
1150
1151
- find_file `(filename: string)`
1151
1152
- search_node
1152
1153
- collapse_all `(keep_buffers?: bool)`
Original file line number Diff line number Diff line change @@ -32,6 +32,7 @@ Api.tree.change_root_to_node = inject_node(function(node)
32
32
end )
33
33
Api .tree .change_root_to_parent = inject_node (require (" nvim-tree.actions.root.dir-up" ).fn )
34
34
Api .tree .get_node_under_cursor = require (" nvim-tree.lib" ).get_node_at_cursor
35
+ Api .tree .get_nodes = require (" nvim-tree.lib" ).get_nodes
35
36
Api .tree .find_file = require (" nvim-tree.actions.finders.find-file" ).fn
36
37
Api .tree .search_node = require (" nvim-tree.actions.finders.search-node" ).fn
37
38
Api .tree .collapse_all = require (" nvim-tree.actions.tree-modifiers.collapse-all" ).fn
Original file line number Diff line number Diff line change @@ -32,6 +32,45 @@ function M.get_node_at_cursor()
32
32
return utils .get_nodes_by_line (core .get_explorer ().nodes , core .get_nodes_starting_line ())[line ]
33
33
end
34
34
35
+ --- Create a sanitized partial copy of a node, populating children recursively.
36
+ --- @param node table
37
+ --- @return table | nil cloned node
38
+ local function clone_node (node )
39
+ if not node then
40
+ node = core .get_explorer ()
41
+ if not node then
42
+ return nil
43
+ end
44
+ end
45
+
46
+ local n = {
47
+ absolute_path = node .absolute_path ,
48
+ executable = node .executable ,
49
+ extension = node .extension ,
50
+ git_status = node .git_status ,
51
+ has_children = node .has_children ,
52
+ hidden = node .hidden ,
53
+ link_to = node .link_to ,
54
+ name = node .name ,
55
+ open = node .open ,
56
+ type = node .type ,
57
+ }
58
+
59
+ if type (node .nodes ) == " table" then
60
+ n .nodes = {}
61
+ for _ , child in ipairs (node .nodes ) do
62
+ table.insert (n .nodes , clone_node (child ))
63
+ end
64
+ end
65
+
66
+ return n
67
+ end
68
+
69
+ --- Api.tree.get_nodes
70
+ function M .get_nodes ()
71
+ return clone_node (core .get_explorer ())
72
+ end
73
+
35
74
-- If node is grouped, return the last node in the group. Otherwise, return the given node.
36
75
function M .get_last_group_node (node )
37
76
local next = node
You can’t perform that action at this time.
0 commit comments