Skip to content

Commit 5bea2b3

Browse files
authored
fix(#3101): when renderer.highlight_opened_files = "none" do not reload on BufUnload and BufReadPost (#3102)
* fix(#3101): fix bad reference to renderer.highlight_opened_files during BufUnload and BufReadPost * fix(#3101): only redraw renderer.highlight_opened_files during BufUnload and BufReadPost * fix(#3101): only redraw renderer.highlight_opened_files during BufUnload and BufReadPost * fix(#3101): only redraw renderer.highlight_opened_files during BufUnload and BufReadPost
1 parent c3c1935 commit 5bea2b3

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

Diff for: lua/nvim-tree/explorer/init.lua

+22-2
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,19 @@ function Explorer:create_autocmds()
101101
vim.api.nvim_create_autocmd("BufReadPost", {
102102
group = self.augroup_id,
103103
callback = function(data)
104-
if (self.filters.state.no_buffer or self.opts.highlight_opened_files ~= "none") and vim.bo[data.buf].buftype == "" then
104+
-- only handle normal files
105+
if vim.bo[data.buf].buftype ~= "" then
106+
return
107+
end
108+
109+
if self.filters.state.no_buffer then
110+
-- full reload is required to update the filter state
105111
utils.debounce("Buf:filter_buffer_" .. self.uid_explorer, self.opts.view.debounce_delay, function()
106112
self:reload_explorer()
107113
end)
114+
elseif self.opts.renderer.highlight_opened_files ~= "none" then
115+
-- draw to update opened highlight
116+
self.renderer:draw()
108117
end
109118
end,
110119
})
@@ -113,10 +122,21 @@ function Explorer:create_autocmds()
113122
vim.api.nvim_create_autocmd("BufUnload", {
114123
group = self.augroup_id,
115124
callback = function(data)
116-
if (self.filters.state.no_buffer or self.opts.highlight_opened_files ~= "none") and vim.bo[data.buf].buftype == "" then
125+
-- only handle normal files
126+
if vim.bo[data.buf].buftype ~= "" then
127+
return
128+
end
129+
130+
if self.filters.state.no_buffer then
131+
-- full reload is required to update the filter state
117132
utils.debounce("Buf:filter_buffer_" .. self.uid_explorer, self.opts.view.debounce_delay, function()
118133
self:reload_explorer()
119134
end)
135+
elseif self.opts.renderer.highlight_opened_files ~= "none" then
136+
-- draw to update opened highlight; must be delayed as the buffer is still loaded during BufUnload
137+
vim.schedule(function()
138+
self.renderer:draw()
139+
end)
120140
end
121141
end,
122142
})

0 commit comments

Comments
 (0)