From 4648ed49f061e1535e2f80def9e1101d69d7d435 Mon Sep 17 00:00:00 2001 From: doot Date: Sat, 24 Dec 2022 19:13:23 +0800 Subject: [PATCH] fix(#1836):add view.debounce_delay to avoid some unnecessary explorer reloads --- doc/nvim-tree-lua.txt | 6 ++++++ lua/nvim-tree.lua | 9 +++++++-- lua/nvim-tree/view.lua | 1 + 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/doc/nvim-tree-lua.txt b/doc/nvim-tree-lua.txt index 9c4b33f3ca7..95f9f55f80f 100644 --- a/doc/nvim-tree-lua.txt +++ b/doc/nvim-tree-lua.txt @@ -190,6 +190,7 @@ Subsequent calls to setup will replace the previous configuration. view = { adaptive_size = false, centralize_selection = false, + debounce_delay = 15, width = 30, hide_root_folder = false, side = "left", @@ -680,6 +681,11 @@ Window / buffer setup. initially centralized, see |zz|. Type: `boolean`, Default: `false` + *nvim-tree.view.debounce_delay* + Idle milliseconds between BufReadPost, BufUnload and update. + The last BufReadPost or BufUnload will be focused, others are discarded. + Type: `number`, Default: `15` (ms) + *nvim-tree.view.hide_root_folder* Hide the path of the current working directory on top of the tree. Type: `boolean`, Default: `false` diff --git a/lua/nvim-tree.lua b/lua/nvim-tree.lua index 63863a3dd90..cd616b12543 100644 --- a/lua/nvim-tree.lua +++ b/lua/nvim-tree.lua @@ -368,7 +368,9 @@ local function setup_autocommands(opts) (filters.config.filter_no_buffer or renderer.config.highlight_opened_files ~= "none") and vim.bo[data.buf].buftype == "" then - reloaders.reload_explorer() + utils.debounce("BufReadPost:filter_buffer", view.debounce_delay, function() + reloaders.reload_explorer() + end) end end, }) @@ -380,7 +382,9 @@ local function setup_autocommands(opts) (filters.config.filter_no_buffer or renderer.config.highlight_opened_files ~= "none") and vim.bo[data.buf].buftype == "" then - reloaders.reload_explorer(nil, data.buf) + utils.debounce("BufUnload:filter_buffer", view.debounce_delay, function() + reloaders.reload_explorer(nil, data.buf) + end) end end, }) @@ -499,6 +503,7 @@ local DEFAULT_OPTS = { -- BEGIN_DEFAULT_OPTS view = { adaptive_size = false, centralize_selection = false, + debounce_delay = 15, width = 30, hide_root_folder = false, side = "left", diff --git a/lua/nvim-tree/view.lua b/lua/nvim-tree/view.lua index f843cb65f40..eccdd1e3c65 100644 --- a/lua/nvim-tree/view.lua +++ b/lua/nvim-tree/view.lua @@ -483,6 +483,7 @@ function M.setup(opts) local options = opts.view or {} M.View.adaptive_size = options.adaptive_size M.View.centralize_selection = options.centralize_selection + M.View.debounce_delay = options.debounce_delay M.View.side = (options.side == "right") and "right" or "left" M.View.width = options.width M.View.height = options.height