Skip to content

Commit 9c97e64

Browse files
authored
fix(#1961): stop unnecessary find file refreshes, avoid find file refresh cycles (#2010)
1 parent 66c15af commit 9c97e64

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

lua/nvim-tree/actions/finders/find-file.lua

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,10 @@ function M.fn(fname)
3030

3131
local profile = log.profile_start("find file %s", fname_real)
3232

33-
-- we cannot wait for watchers
34-
reload.refresh_nodes_for_path(vim.fn.fnamemodify(fname_real, ":h"))
33+
-- we cannot wait for watchers to populate a new node
34+
if utils.get_node_from_path(fname_real) == nil then
35+
reload.refresh_nodes_for_path(vim.fn.fnamemodify(fname_real, ":h"))
36+
end
3537

3638
local line = core.get_nodes_starting_line()
3739

lua/nvim-tree/explorer/reload.lua

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,9 @@ function M.refresh_nodes_for_path(path)
166166

167167
local profile = log.profile_start("refresh_nodes_for_path %s", path)
168168

169+
-- avoids cycles
170+
local absolute_paths_refreshed = {}
171+
169172
NodeIterator.builder({ explorer })
170173
:hidden()
171174
:recursor(function(node)
@@ -177,10 +180,13 @@ function M.refresh_nodes_for_path(path)
177180
end
178181
end)
179182
:applier(function(node)
180-
local abs_contains = node.absolute_path and path:match("^" .. node.absolute_path)
181-
local link_contains = node.link_to and path:match("^" .. node.link_to)
183+
local abs_contains = node.absolute_path and path:find(node.absolute_path, 1, true) == 1
184+
local link_contains = node.link_to and path:find(node.link_to, 1, true) == 1
182185
if abs_contains or link_contains then
183-
M.refresh_node(node)
186+
if not absolute_paths_refreshed[node.absolute_path] then
187+
absolute_paths_refreshed[node.absolute_path] = true
188+
M.refresh_node(node)
189+
end
184190
end
185191
end)
186192
:iterate()

0 commit comments

Comments
 (0)