Skip to content

Commit a8d26bb

Browse files
committed
Revert "fix(#1815): don't schedule find_file calls, debounce update_focused_file with 15ms default (#1820)"
This reverts commit 623cecb.
1 parent 623cecb commit a8d26bb

File tree

2 files changed

+13
-29
lines changed

2 files changed

+13
-29
lines changed

doc/nvim-tree-lua.txt

-6
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,6 @@ Subsequent calls to setup will replace the previous configuration.
280280
},
281281
update_focused_file = {
282282
enable = false,
283-
debounce_delay = 15,
284283
update_root = false,
285284
ignore_list = {},
286285
},
@@ -508,11 +507,6 @@ until it finds the file.
508507
Enable this feature.
509508
Type: `boolean`, Default: `false`
510509

511-
*nvim-tree.update_focused_file.debounce_delay*
512-
Idle milliseconds between BufEnter and update.
513-
The last BufEnter will be focused, others are discarded.
514-
Type: `number`, Default: `15` (ms)
515-
516510
*nvim-tree.update_focused_file.update_root* (previously `update_focused_file.update_cwd`)
517511
Update the root directory of the tree if the file is not under current
518512
root directory. It prefers vim's cwd and `root_dirs`.

lua/nvim-tree.lua

+13-23
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ function M.toggle(find_file, no_focus, cwd, bang)
7676
local previous_buf = vim.api.nvim_get_current_buf()
7777
M.open(cwd)
7878
if _config.update_focused_file.enable or find_file then
79-
find_file(false, previous_buf, bang)
79+
M.find_file(false, previous_buf, bang)
8080
end
8181
if no_focus then
8282
vim.cmd "noautocmd wincmd p"
@@ -143,7 +143,7 @@ local function is_file_readable(fname)
143143
return stat and stat.type == "file" and vim.loop.fs_access(fname, "R")
144144
end
145145

146-
local function find_file(with_open, bufnr, bang)
146+
function M.find_file(with_open, bufnr, bang)
147147
if not with_open and not core.get_explorer() then
148148
return
149149
end
@@ -162,20 +162,13 @@ local function find_file(with_open, bufnr, bang)
162162
M.open()
163163
end
164164

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)
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)
179172
end
180173

181174
M.resize = view.resize
@@ -279,7 +272,7 @@ function M.on_enter(netrw_disabled)
279272
if should_focus_other_window then
280273
vim.cmd "noautocmd wincmd p"
281274
if should_find then
282-
find_file(false)
275+
M.find_file(false)
283276
end
284277
end
285278
end
@@ -313,7 +306,7 @@ local function setup_vim_commands()
313306
vim.api.nvim_create_user_command("NvimTreeRefresh", reloaders.reload_explorer, { bar = true })
314307
vim.api.nvim_create_user_command("NvimTreeClipboard", copy_paste.print_clipboard, { bar = true })
315308
vim.api.nvim_create_user_command("NvimTreeFindFile", function(res)
316-
find_file(true, nil, res.bang)
309+
M.find_file(true, nil, res.bang)
317310
end, { bang = true, bar = true })
318311
vim.api.nvim_create_user_command("NvimTreeFindFileToggle", function(res)
319312
M.toggle(true, false, res.args, res.bang)
@@ -331,7 +324,7 @@ function M.change_dir(name)
331324
change_dir.fn(name)
332325

333326
if _config.update_focused_file.enable then
334-
find_file(false)
327+
M.find_file(false)
335328
end
336329
end
337330

@@ -407,9 +400,7 @@ local function setup_autocommands(opts)
407400
if opts.update_focused_file.enable then
408401
create_nvim_tree_autocmd("BufEnter", {
409402
callback = function()
410-
utils.debounce("BufEnter:find_file", opts.update_focused_file.debounce_delay, function()
411-
find_file(false)
412-
end)
403+
M.find_file(false)
413404
end,
414405
})
415406
end
@@ -581,7 +572,6 @@ local DEFAULT_OPTS = { -- BEGIN_DEFAULT_OPTS
581572
},
582573
update_focused_file = {
583574
enable = false,
584-
debounce_delay = 15,
585575
update_root = false,
586576
ignore_list = {},
587577
},

0 commit comments

Comments
 (0)