@@ -362,35 +362,9 @@ M.get_items_async = function(state, parent_id, path_to_reveal, callback)
362
362
M .get_items (state , parent_id , path_to_reveal , callback , true )
363
363
end
364
364
365
- M .get_items = function (state , parent_id , path_to_reveal , callback , async , recursive )
366
- if state .async_directory_scan == " always" then
367
- async = true
368
- elseif state .async_directory_scan == " never" then
369
- async = false
370
- elseif type (async ) == " nil" then
371
- async = (state .async_directory_scan == " auto" ) or state .async_directory_scan
372
- end
373
-
374
- if not parent_id then
375
- M .stop_watchers (state )
376
- end
377
- local context = file_items .create_context ()
378
- context .state = state
379
- context .parent_id = parent_id
380
- context .path_to_reveal = path_to_reveal
381
- context .recursive = recursive
382
- context .callback = callback
383
-
384
- -- Create root folder
385
- local root = file_items .create_item (context , parent_id or state .path , " directory" )
386
- root .name = vim .fn .fnamemodify (root .path , " :~" )
387
- root .loaded = true
388
- root .search_pattern = state .search_pattern
389
- context .root = root
390
- context .folders [root .path ] = root
391
- state .default_expanded_nodes = state .force_open_folders or { state .path }
392
-
393
- if state .search_pattern then
365
+ local handle_search_pattern = function (context )
366
+ local state = context .state
367
+ local root = context .root
394
368
local search_opts = {
395
369
filtered_items = state .filtered_items ,
396
370
find_command = state .find_command ,
@@ -417,9 +391,12 @@ M.get_items = function(state, parent_id, path_to_reveal, callback, async, recurs
417
391
-- Use the external command because the plenary search is slow
418
392
filter_external .find_files (search_opts )
419
393
end
420
- else
421
- -- In the case of a refresh or navigating up, we need to make sure that all
422
- -- open folders are loaded.
394
+ end
395
+
396
+ local handle_refresh_or_up = function (context , async )
397
+ local parent_id = context .parent_id
398
+ local path_to_reveal = context .path_to_reveal
399
+ local state = context .state
423
400
local path = parent_id or state .path
424
401
context .paths_to_load = {}
425
402
if parent_id == nil then
@@ -473,6 +450,42 @@ M.get_items = function(state, parent_id, path_to_reveal, callback, async, recurs
473
450
else
474
451
sync_scan (context , path )
475
452
end
453
+ end
454
+
455
+ M .get_items = function (state , parent_id , path_to_reveal , callback , async , recursive )
456
+ if state .async_directory_scan == " always" then
457
+ async = true
458
+ elseif state .async_directory_scan == " never" then
459
+ async = false
460
+ elseif type (async ) == " nil" then
461
+ async = (state .async_directory_scan == " auto" ) or state .async_directory_scan
462
+ end
463
+
464
+ if not parent_id then
465
+ M .stop_watchers (state )
466
+ end
467
+ local context = file_items .create_context ()
468
+ context .state = state
469
+ context .parent_id = parent_id
470
+ context .path_to_reveal = path_to_reveal
471
+ context .recursive = recursive
472
+ context .callback = callback
473
+
474
+ -- Create root folder
475
+ local root = file_items .create_item (context , parent_id or state .path , " directory" )
476
+ root .name = vim .fn .fnamemodify (root .path , " :~" )
477
+ root .loaded = true
478
+ root .search_pattern = state .search_pattern
479
+ context .root = root
480
+ context .folders [root .path ] = root
481
+ state .default_expanded_nodes = state .force_open_folders or { state .path }
482
+
483
+ if state .search_pattern then
484
+ handle_search_pattern (context )
485
+ else
486
+ -- In the case of a refresh or navigating up, we need to make sure that all
487
+ -- open folders are loaded.
488
+ handle_refresh_or_up (context , async )
476
489
end
477
490
end
478
491
0 commit comments