Skip to content

Commit 34c6f07

Browse files
committed
chore: add should_expand in DirectoryNode to avoid circular dependecy
1 parent 8f3fd20 commit 34c6f07

File tree

2 files changed

+22
-22
lines changed

2 files changed

+22
-22
lines changed

lua/nvim-tree/node/directory.lua

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,28 @@ function DirectoryNode:descend_until_empty()
327327
return not should_exclude
328328
end
329329

330+
---@param expansion_count integer
331+
---@param should_descend fun(expansion_count: integer, node: Node): boolean
332+
---@return boolean
333+
function DirectoryNode:should_expand(expansion_count, should_descend)
334+
if not self.open and should_descend(expansion_count, self) then
335+
if #self.nodes == 0 then
336+
self.explorer:expand_dir_node(self) -- populate node.group_next
337+
end
338+
339+
if self.group_next then
340+
local expand_next = self.group_next:should_expand(expansion_count, should_descend)
341+
if expand_next then
342+
self.open = true
343+
end
344+
return expand_next
345+
else
346+
return true
347+
end
348+
end
349+
return false
350+
end
351+
330352
---@param expand_opts ApiTreeExpandOpts?
331353
function DirectoryNode:expand(expand_opts)
332354
local expansion_count = 0

lua/nvim-tree/node/init.lua

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -148,28 +148,6 @@ end
148148
---@param should_descend fun(expansion_count: integer, node: Node): boolean
149149
---@return boolean
150150
function Node:should_expand(expansion_count, should_descend)
151-
local DirectoryNode = require("nvim-tree.node.directory")
152-
153-
local dir = self:as(DirectoryNode)
154-
if not dir then
155-
return false
156-
end
157-
158-
if not dir.open and should_descend(expansion_count, self) then
159-
if #self.nodes == 0 then
160-
self.explorer:expand_dir_node(dir) -- populate node.group_next
161-
end
162-
163-
if dir.group_next then
164-
local expand_next = dir.group_next:should_expand(expansion_count, should_descend)
165-
if expand_next then
166-
dir.open = true
167-
end
168-
return expand_next
169-
else
170-
return true
171-
end
172-
end
173151
return false
174152
end
175153

0 commit comments

Comments
 (0)