@@ -76,7 +76,7 @@ function M.toggle(find_file, no_focus, cwd, bang)
76
76
local previous_buf = vim .api .nvim_get_current_buf ()
77
77
M .open (cwd )
78
78
if _config .update_focused_file .enable or find_file then
79
- M . find_file (false , previous_buf , bang )
79
+ find_file (false , previous_buf , bang )
80
80
end
81
81
if no_focus then
82
82
vim .cmd " noautocmd wincmd p"
@@ -143,7 +143,7 @@ local function is_file_readable(fname)
143
143
return stat and stat .type == " file" and vim .loop .fs_access (fname , " R" )
144
144
end
145
145
146
- function M . find_file (with_open , bufnr , bang )
146
+ local function find_file (with_open , bufnr , bang )
147
147
if not with_open and not core .get_explorer () then
148
148
return
149
149
end
@@ -162,13 +162,20 @@ function M.find_file(with_open, bufnr, bang)
162
162
M .open ()
163
163
end
164
164
165
- -- if we don't schedule, it will search for NvimTree
166
- vim .schedule (function ()
167
- if bang or _config .update_focused_file .update_root then
168
- M .change_root (filepath , bufnr )
169
- end
170
- require (" nvim-tree.actions.finders.find-file" ).fn (filepath )
171
- end )
165
+ if bang or _config .update_focused_file .update_root then
166
+ M .change_root (filepath , bufnr )
167
+ end
168
+
169
+ require (" nvim-tree.actions.finders.find-file" ).fn (filepath )
170
+ end
171
+
172
+ --- @deprecated 2022/12/16
173
+ function M .find_file (with_open , bufnr , bang )
174
+ vim .notify_once (
175
+ " require('nvim-tree').find_file is not API and will soon be unavailable. Please use api.tree.find_file as per :help nvim-tree-api" ,
176
+ vim .log .levels .WARN
177
+ )
178
+ find_file (with_open , bufnr , bang )
172
179
end
173
180
174
181
M .resize = view .resize
@@ -272,7 +279,7 @@ function M.on_enter(netrw_disabled)
272
279
if should_focus_other_window then
273
280
vim .cmd " noautocmd wincmd p"
274
281
if should_find then
275
- M . find_file (false )
282
+ find_file (false )
276
283
end
277
284
end
278
285
end
@@ -306,7 +313,7 @@ local function setup_vim_commands()
306
313
vim .api .nvim_create_user_command (" NvimTreeRefresh" , reloaders .reload_explorer , { bar = true })
307
314
vim .api .nvim_create_user_command (" NvimTreeClipboard" , copy_paste .print_clipboard , { bar = true })
308
315
vim .api .nvim_create_user_command (" NvimTreeFindFile" , function (res )
309
- M . find_file (true , nil , res .bang )
316
+ find_file (true , nil , res .bang )
310
317
end , { bang = true , bar = true })
311
318
vim .api .nvim_create_user_command (" NvimTreeFindFileToggle" , function (res )
312
319
M .toggle (true , false , res .args , res .bang )
@@ -324,7 +331,7 @@ function M.change_dir(name)
324
331
change_dir .fn (name )
325
332
326
333
if _config .update_focused_file .enable then
327
- M . find_file (false )
334
+ find_file (false )
328
335
end
329
336
end
330
337
@@ -400,7 +407,9 @@ local function setup_autocommands(opts)
400
407
if opts .update_focused_file .enable then
401
408
create_nvim_tree_autocmd (" BufEnter" , {
402
409
callback = function ()
403
- M .find_file (false )
410
+ utils .debounce (" BufEnter:find_file" , opts .update_focused_file .debounce_delay , function ()
411
+ find_file (false )
412
+ end )
404
413
end ,
405
414
})
406
415
end
@@ -572,6 +581,7 @@ local DEFAULT_OPTS = { -- BEGIN_DEFAULT_OPTS
572
581
},
573
582
update_focused_file = {
574
583
enable = false ,
584
+ debounce_delay = 15 ,
575
585
update_root = false ,
576
586
ignore_list = {},
577
587
},
0 commit comments