File tree Expand file tree Collapse file tree 5 files changed +26
-29
lines changed Expand file tree Collapse file tree 5 files changed +26
-29
lines changed Original file line number Diff line number Diff line change @@ -125,7 +125,7 @@ function M.place_cursor_on_node()
125125 if not node or node .name == " .." then
126126 return
127127 end
128- node = utils . get_parent_of_group (node )
128+ node = node : get_parent_of_group ()
129129
130130 local line = vim .api .nvim_get_current_line ()
131131 local cursor = vim .api .nvim_win_get_cursor (0 )
Original file line number Diff line number Diff line change @@ -21,7 +21,7 @@ function M.fn(should_close)
2121 return
2222 end
2323
24- local parent = utils . get_parent_of_group (node ).parent
24+ local parent = node : get_parent_of_group ().parent
2525
2626 if not parent or not parent .parent then
2727 return view .set_cursor { 1 , 0 }
Original file line number Diff line number Diff line change @@ -79,19 +79,6 @@ function M.ungroup_empty_folders(node)
7979 end
8080end
8181
82- --- TODO move to node
83- --- @param node Node
84- --- @return Node[]
85- function M .get_all_nodes_in_group (node )
86- local next_node = utils .get_parent_of_group (node )
87- local nodes = {}
88- while next_node do
89- table.insert (nodes , next_node )
90- next_node = next_node .group_next
91- end
92- return nodes
93- end
94-
9582--- TODO move to node
9683-- Toggle group empty folders
9784--- @param head_node Node
@@ -119,7 +106,7 @@ function M.expand_or_collapse(node, toggle_group)
119106 explorer :expand (node )
120107 end
121108
122- local head_node = utils . get_parent_of_group (node )
109+ local head_node = node : get_parent_of_group ()
123110 if toggle_group then
124111 toggle_group_folders (head_node )
125112 end
@@ -131,7 +118,7 @@ function M.expand_or_collapse(node, toggle_group)
131118 else
132119 next_open = not open
133120 end
134- for _ , n in ipairs (M . get_all_nodes_in_group (head_node )) do
121+ for _ , n in ipairs (head_node : get_all_nodes_in_group ()) do
135122 n .open = next_open
136123 end
137124
Original file line number Diff line number Diff line change 11local git = require " nvim-tree.git"
2- local utils = require " nvim-tree.utils"
32
43--- Abstract Node class.
54--- Uses the abstract factory pattern to instantiate child instances.
217216
218217--- Refresh contents and git status for a single node
219218function BaseNode :refresh ()
220- local parent_node = utils . get_parent_of_group (self )
219+ local parent_node = self : get_parent_of_group ()
221220 local toplevel = git .get_toplevel (self .absolute_path )
222221
223222 git .reload_project (toplevel , self .absolute_path , function ()
@@ -231,6 +230,27 @@ function BaseNode:refresh()
231230 end )
232231end
233232
233+ --- Get the highest parent of grouped nodes
234+ --- @return Node node or parent
235+ function BaseNode :get_parent_of_group ()
236+ local node = self
237+ while node and node .parent and node .parent .group_next do
238+ node = node .parent or node
239+ end
240+ return node
241+ end
242+
243+ --- @return Node[]
244+ function BaseNode :get_all_nodes_in_group ()
245+ local next_node = self :get_parent_of_group ()
246+ local nodes = {}
247+ while next_node do
248+ table.insert (nodes , next_node )
249+ next_node = next_node .group_next
250+ end
251+ return nodes
252+ end
253+
234254--- Create a sanitized partial copy of a node, populating children recursively.
235255--- @return BaseNode cloned
236256function BaseNode :clone ()
Original file line number Diff line number Diff line change @@ -173,16 +173,6 @@ function M.get_node_from_path(path)
173173 :iterate ()
174174end
175175
176- --- Get the highest parent of grouped nodes
177- --- @param node Node
178- --- @return Node node or parent
179- function M .get_parent_of_group (node )
180- while node and node .parent and node .parent .group_next do
181- node = node .parent or node
182- end
183- return node
184- end
185-
186176M .default_format_hidden_count = function (hidden_count , simple )
187177 local parts = {}
188178 local total_count = 0
You can’t perform that action at this time.
0 commit comments