fix(#1836): add view.debounce_delay (#1871)

* fix(#1836):add view.debounce_delay to avoid some unnecessary explorer reloads

* fixed BufReadPost & BufUnload nil pointer

* update_focused_file.debouce_delay to view.debounce_delay

* changed docs to be more accurate

* added debounce on modified update

* Using same event for filter buffer

* removed unused View.debounce_delay

* changed docs to be more accurate

Co-authored-by: doot <gugegby@gmail.com>
Co-authored-by: Alexander Courtis <alex@courtis.org>
This commit is contained in:
Richard Li 2023-01-02 09:32:56 +13:00 committed by GitHub
parent e322fbb80b
commit 951b6e7e55
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 12 deletions

View File

@ -192,6 +192,7 @@ Subsequent calls to setup will replace the previous configuration.
adaptive_size = false,
centralize_selection = false,
cursorline = true,
debounce_delay = 15,
width = 30,
hide_root_folder = false,
side = "left",
@ -286,7 +287,6 @@ Subsequent calls to setup will replace the previous configuration.
},
update_focused_file = {
enable = false,
debounce_delay = 15,
update_root = false,
ignore_list = {},
},
@ -520,11 +520,6 @@ until it finds the file.
Enable this feature.
Type: `boolean`, Default: `false`
*nvim-tree.update_focused_file.debounce_delay*
Idle milliseconds between BufEnter and update.
The last BufEnter will be focused, others are discarded.
Type: `number`, Default: `15` (ms)
*nvim-tree.update_focused_file.update_root* (previously `update_focused_file.update_cwd`)
Update the root directory of the tree if the file is not under current
root directory. It prefers vim's cwd and `root_dirs`.
@ -716,6 +711,11 @@ Window / buffer setup.
Enable |cursorline| in the tree window.
Type: `boolean`, Default: `true`
*nvim-tree.view.debounce_delay*
Idle milliseconds before some reload / refresh operations.
Increase if you experience performance issues around screen refresh.
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`

View File

@ -369,7 +369,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("Buf:filter_buffer", opts.view.debounce_delay, function()
reloaders.reload_explorer()
end)
end
end,
})
@ -381,7 +383,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("Buf:filter_buffer", opts.view.debounce_delay, function()
reloaders.reload_explorer(nil, data.buf)
end)
end
end,
})
@ -416,7 +420,7 @@ local function setup_autocommands(opts)
if opts.update_focused_file.enable then
create_nvim_tree_autocmd("BufEnter", {
callback = function()
utils.debounce("BufEnter:find_file", opts.update_focused_file.debounce_delay, function()
utils.debounce("BufEnter:find_file", opts.view.debounce_delay, function()
find_file(false)
end)
end,
@ -481,8 +485,10 @@ local function setup_autocommands(opts)
if opts.modified.enable then
create_nvim_tree_autocmd({ "BufModifiedSet", "BufWritePost" }, {
callback = function()
modified.reload()
reloaders.reload_explorer()
utils.debounce("Buf:modified", opts.view.debounce_delay, function()
modified.reload()
reloaders.reload_explorer()
end)
end,
})
end
@ -510,6 +516,7 @@ local DEFAULT_OPTS = { -- BEGIN_DEFAULT_OPTS
adaptive_size = false,
centralize_selection = false,
cursorline = true,
debounce_delay = 15,
width = 30,
hide_root_folder = false,
side = "left",
@ -604,7 +611,6 @@ local DEFAULT_OPTS = { -- BEGIN_DEFAULT_OPTS
},
update_focused_file = {
enable = false,
debounce_delay = 15,
update_root = false,
ignore_list = {},
},

View File

@ -24,6 +24,9 @@ local function refactored(opts)
-- 2022/11/22
utils.move_missing_val(opts, "renderer", "root_folder_modifier", opts, "renderer", "root_folder_label", true)
-- 2023/01/01
utils.move_missing_val(opts, "update_focused_file", "debounce_delay", opts, "view", "debounce_delay", true)
end
local function removed(opts)