@@ -7,6 +7,7 @@ local fs_scan = require("neo-tree.sources.filesystem.lib.fs_scan")
77local renderer = require (" neo-tree.ui.renderer" )
88local inputs = require (" neo-tree.ui.inputs" )
99local events = require (" neo-tree.events" )
10+ local log = require (" neo-tree.log" )
1011
1112local M = {}
1213local default_config = nil
@@ -98,6 +99,7 @@ M.focus = function(path_to_reveal, callback)
9899end
99100
100101local navigate_internal = function (path , path_to_reveal , callback )
102+ log .trace (" navigate_internal" , path , path_to_reveal )
101103 local state = get_state ()
102104 local pos = utils .get_value (state , " window.position" , " left" )
103105 local was_float = state .force_float or pos == " float"
@@ -116,6 +118,7 @@ local navigate_internal = function(path, path_to_reveal, callback)
116118 if callback then
117119 callback ()
118120 end
121+ state .in_navigate = false
119122 end )
120123 else
121124 local previously_focused = nil
@@ -137,6 +140,7 @@ local navigate_internal = function(path, path_to_reveal, callback)
137140 if callback then
138141 callback ()
139142 end
143+ state .in_navigate = false
140144 end )
141145 end
142146
@@ -150,12 +154,16 @@ end
150154--- @param path_to_reveal string Node to focus after the items are loaded.
151155--- @param callback function Callback to call after the items are loaded.
152156M .navigate = function (path , path_to_reveal , callback )
157+ log .trace (" navigate" , path , path_to_reveal )
158+ local state = get_state ()
159+ state .in_navigate = true
153160 utils .debounce (" filesystem_navigate" , function ()
154161 navigate_internal (path , path_to_reveal , callback )
155162 end , 100 )
156163end
157164
158165M .reveal_current_file = function (toggle_if_open )
166+ log .trace (" Revealing current file" )
159167 if toggle_if_open then
160168 if M .close () then
161169 -- It was open, and now it's not.
@@ -191,15 +199,20 @@ M.reveal_current_file = function(toggle_if_open)
191199end
192200
193201M .reset_search = function (refresh )
202+ log .trace (" reset_search" )
203+ local state = get_state ()
194204 if refresh == nil then
195205 refresh = true
196206 end
197- local state = get_state ()
198207 if state .open_folders_before_search then
199- renderer .set_expanded_nodes (state .tree , state .open_folders_before_search )
200- state .open_folders_before_search = nil
208+ log .trace (" reset_search: open_folders_before_search" )
209+ state .force_open_folders = utils .table_copy (state .open_folders_before_search )
210+ else
211+ log .trace (" reset_search: why are there no open_folders_before_search?" )
212+ state .force_open_folders = nil
201213 end
202214 state .search_pattern = nil
215+ state .open_folders_before_search = nil
203216 if refresh then
204217 M .refresh ()
205218 end
246259
247260--- Refreshes the tree by scanning the filesystem again.
248261M .refresh = function (callback )
262+ log .trace (" filesystem refresh" )
249263 local state = get_state ()
264+ if state .in_navigate or state .in_show_nodes then
265+ return
266+ end
250267 if state .path and renderer .window_exists (state ) then
251268 if type (callback ) ~= " function" then
252269 callback = nil
@@ -270,14 +287,22 @@ M.setup = function(config, global_config)
270287 -- convert to new event system
271288 events .subscribe ({
272289 event = events .BEFORE_RENDER ,
273- handler = config .before_render ,
290+ handler = function (state )
291+ local this_state = get_state ()
292+ if state == this_state then
293+ config .before_render (this_state )
294+ end
295+ end ,
274296 id = before_render_id ,
275297 })
276298 elseif global_config .enable_git_status then
277299 events .subscribe ({
278300 event = events .BEFORE_RENDER ,
279301 handler = function (state )
280- state .git_status_lookup = utils .get_git_status ()
302+ local this_state = get_state ()
303+ if state == this_state then
304+ state .git_status_lookup = utils .get_git_status ()
305+ end
281306 end ,
282307 id = before_render_id ,
283308 })
0 commit comments