File tree 5 files changed +26
-30
lines changed
5 files changed +26
-30
lines changed Original file line number Diff line number Diff line change @@ -125,7 +125,7 @@ function M.place_cursor_on_node()
125
125
if not node or node .name == " .." then
126
126
return
127
127
end
128
- node = utils . get_parent_of_group (node )
128
+ node = node : get_parent_of_group ()
129
129
130
130
local line = vim .api .nvim_get_current_line ()
131
131
local cursor = vim .api .nvim_win_get_cursor (0 )
Original file line number Diff line number Diff line change @@ -20,7 +20,7 @@ function M.fn(should_close)
20
20
return
21
21
end
22
22
23
- local parent = utils . get_parent_of_group (node ).parent
23
+ local parent = node : get_parent_of_group ().parent
24
24
25
25
if not parent or not parent .parent then
26
26
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)
79
79
end
80
80
end
81
81
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
-
95
82
--- TODO move to node
96
83
-- Toggle group empty folders
97
84
--- @param head_node Node
@@ -119,7 +106,7 @@ function M.expand_or_collapse(node, toggle_group)
119
106
explorer :expand (node )
120
107
end
121
108
122
- local head_node = utils . get_parent_of_group (node )
109
+ local head_node = node : get_parent_of_group ()
123
110
if toggle_group then
124
111
toggle_group_folders (head_node )
125
112
end
@@ -131,7 +118,7 @@ function M.expand_or_collapse(node, toggle_group)
131
118
else
132
119
next_open = not open
133
120
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
135
122
n .open = next_open
136
123
end
137
124
Original file line number Diff line number Diff line change 1
1
local git = require (" nvim-tree.git" )
2
- local utils = require (" nvim-tree.utils" )
3
2
4
3
--- Abstract Node class.
5
4
--- Uses the abstract factory pattern to instantiate child instances.
217
216
218
217
--- Refresh contents and git status for a single node
219
218
function BaseNode :refresh ()
220
- local parent_node = utils . get_parent_of_group (self )
219
+ local parent_node = self : get_parent_of_group ()
221
220
local toplevel = git .get_toplevel (self .absolute_path )
222
221
223
222
git .reload_project (toplevel , self .absolute_path , function ()
@@ -231,10 +230,30 @@ function BaseNode:refresh()
231
230
end )
232
231
end
233
232
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
+
234
254
--- Create a sanitized partial copy of a node, populating children recursively.
235
255
--- @return BaseNode cloned
236
256
function BaseNode :clone ()
237
-
238
257
--- @type Explorer
239
258
local placeholder
240
259
Original file line number Diff line number Diff line change @@ -173,16 +173,6 @@ function M.get_node_from_path(path)
173
173
:iterate ()
174
174
end
175
175
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
-
186
176
M .default_format_hidden_count = function (hidden_count , simple )
187
177
local parts = {}
188
178
local total_count = 0
You can’t perform that action at this time.
0 commit comments