@@ -15,7 +15,7 @@ local windows = require("neo-tree.ui.windows")
1515local M = { resize_timer_interval = 50 }
1616local ESC_KEY = vim .api .nvim_replace_termcodes (" <ESC>" , true , false , true )
1717local default_popup_size = { width = 60 , height = " 80%" }
18- local draw , create_window , create_tree , render_tree
18+ local draw , create_tree , render_tree
1919
2020local floating_windows = {}
2121local update_floating_windows = function ()
@@ -913,7 +913,14 @@ local get_buffer = function(bufname, state)
913913 return bufnr
914914end
915915
916- create_window = function (state )
916+ M .acquire_window = function (state )
917+ if M .window_exists (state ) then
918+ return state .winid
919+ end
920+
921+ -- used by tests to determine if the tree is ready for testing
922+ state ._ready = false
923+
917924 local default_position = utils .resolve_config_option (state , " window.position" , " left" )
918925 local relative = utils .resolve_config_option (state , " window.relative" , " editor" )
919926 state .current_position = state .current_position or default_position
@@ -954,6 +961,7 @@ create_window = function(state)
954961 local win
955962 if state .current_position == " float" then
956963 M .close_all_floating_windows ()
964+ M .close (state )
957965 win = create_floating_window (state , win_options , bufname )
958966 elseif state .current_position == " current" then
959967 -- state.id is always the window id or tabnr that this state was created for
@@ -1020,7 +1028,7 @@ create_window = function(state)
10201028 end
10211029
10221030 set_buffer_mappings (state )
1023- return win
1031+ return state . winid
10241032end
10251033
10261034M .update_floating_window_layouts = function ()
@@ -1142,8 +1150,13 @@ draw = function(nodes, state, parent_id)
11421150 end
11431151
11441152 -- Create the tree if it doesn't exist.
1145- if not parent_id and not M .window_exists (state ) then
1146- create_window (state )
1153+ if parent_id then
1154+ if not M .window_exists (state ) then
1155+ log .trace (" Window is gone, aborting lazy load of folder" )
1156+ return
1157+ end
1158+ else
1159+ M .acquire_window (state )
11471160 create_tree (state )
11481161 end
11491162
@@ -1174,6 +1187,7 @@ draw = function(nodes, state, parent_id)
11741187 -- Restore the cursor position/focused node in the tree based on the state
11751188 -- when it was last closed
11761189 M .position .restore (state )
1190+ state ._ready = true
11771191end
11781192
11791193local function group_empty_dirs (node )
0 commit comments