Skip to content

Commit 7dcda85

Browse files
committed
fix(#1815): debounce BufEnter find_file
1 parent 2960eea commit 7dcda85

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

doc/nvim-tree-lua.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,11 @@ until it finds the file.
507507
Enable this feature.
508508
Type: `boolean`, Default: `false`
509509

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

lua/nvim-tree.lua

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,9 @@ local function setup_autocommands(opts)
398398
if opts.update_focused_file.enable then
399399
create_nvim_tree_autocmd("BufEnter", {
400400
callback = function()
401-
find_file(false)
401+
utils.debounce("BufEnter:find_file", opts.update_focused_file.debounce_delay, function()
402+
find_file(false)
403+
end)
402404
end,
403405
})
404406
end
@@ -571,6 +573,7 @@ local DEFAULT_OPTS = { -- BEGIN_DEFAULT_OPTS
571573
},
572574
update_focused_file = {
573575
enable = false,
576+
debounce_delay = 50,
574577
update_root = false,
575578
ignore_list = {},
576579
},

0 commit comments

Comments
 (0)