fix(view): refresh opened files highlight on buffer read, unload (#1827)
This commit is contained in:
parent
e8ea62c198
commit
18272f8df3
@ -356,7 +356,7 @@ local function setup_autocommands(opts)
|
||||
|
||||
create_nvim_tree_autocmd("BufReadPost", {
|
||||
callback = function()
|
||||
if filters.config.filter_no_buffer then
|
||||
if filters.config.filter_no_buffer or renderer.config.highlight_opened_files then
|
||||
reloaders.reload_explorer()
|
||||
end
|
||||
end,
|
||||
@ -364,7 +364,7 @@ local function setup_autocommands(opts)
|
||||
|
||||
create_nvim_tree_autocmd("BufUnload", {
|
||||
callback = function(data)
|
||||
if filters.config.filter_no_buffer then
|
||||
if filters.config.filter_no_buffer or renderer.config.highlight_opened_files then
|
||||
reloaders.reload_explorer(nil, data.buf)
|
||||
end
|
||||
end,
|
||||
|
||||
@ -44,7 +44,7 @@ function M.reload_explorer(_, unloaded_bufnr)
|
||||
local projects = git.reload()
|
||||
refresh_nodes(core.get_explorer(), projects, unloaded_bufnr)
|
||||
if view.is_visible() then
|
||||
renderer.draw()
|
||||
renderer.draw(unloaded_bufnr)
|
||||
end
|
||||
event_running = false
|
||||
end
|
||||
|
||||
@ -206,7 +206,7 @@ function Builder:_highlight_opened_files(node, offset, icon_length, git_icons_le
|
||||
self:_insert_highlight("NvimTreeOpenedFile", from, to)
|
||||
end
|
||||
|
||||
function Builder:_build_file(node, padding, git_highlight, git_icons_tbl)
|
||||
function Builder:_build_file(node, padding, git_highlight, git_icons_tbl, unloaded_bufnr)
|
||||
local offset = string.len(padding)
|
||||
|
||||
local icon = self:_build_file_icon(node, offset)
|
||||
@ -228,7 +228,9 @@ function Builder:_build_file(node, padding, git_highlight, git_icons_tbl)
|
||||
self:_insert_highlight("NvimTreeImageFile", col_start, col_end)
|
||||
end
|
||||
|
||||
local should_highlight_opened_files = self.highlight_opened_files and vim.fn.bufloaded(node.absolute_path) > 0
|
||||
local should_highlight_opened_files = self.highlight_opened_files
|
||||
and vim.fn.bufloaded(node.absolute_path) > 0
|
||||
and vim.fn.bufnr(node.absolute_path) ~= unloaded_bufnr
|
||||
if should_highlight_opened_files then
|
||||
self:_highlight_opened_files(node, offset, #icon, git_icons_length)
|
||||
end
|
||||
@ -238,7 +240,7 @@ function Builder:_build_file(node, padding, git_highlight, git_icons_tbl)
|
||||
end
|
||||
end
|
||||
|
||||
function Builder:_build_line(node, idx, num_children)
|
||||
function Builder:_build_line(node, idx, num_children, unloaded_bufnr)
|
||||
local padding = pad.get_padding(self.depth, idx, num_children, node, self.markers)
|
||||
|
||||
if string.len(padding) > 0 then
|
||||
@ -262,13 +264,13 @@ function Builder:_build_line(node, idx, num_children)
|
||||
elseif is_symlink then
|
||||
self:_build_symlink(node, padding, git_highlight, git_icons_tbl)
|
||||
else
|
||||
self:_build_file(node, padding, git_highlight, git_icons_tbl)
|
||||
self:_build_file(node, padding, git_highlight, git_icons_tbl, unloaded_bufnr)
|
||||
end
|
||||
self.index = self.index + 1
|
||||
|
||||
if node.open then
|
||||
self.depth = self.depth + 1
|
||||
self:build(node)
|
||||
self:build(node, unloaded_bufnr)
|
||||
self.depth = self.depth - 1
|
||||
end
|
||||
end
|
||||
@ -287,12 +289,12 @@ function Builder:_get_nodes_number(nodes)
|
||||
return i
|
||||
end
|
||||
|
||||
function Builder:build(tree)
|
||||
function Builder:build(tree, unloaded_bufnr)
|
||||
local num_children = self:_get_nodes_number(tree.nodes)
|
||||
local idx = 1
|
||||
for _, node in ipairs(tree.nodes) do
|
||||
if not node.hidden then
|
||||
self:_build_line(node, idx, num_children)
|
||||
self:_build_line(node, idx, num_children, unloaded_bufnr)
|
||||
idx = idx + 1
|
||||
end
|
||||
end
|
||||
|
||||
@ -46,7 +46,7 @@ local picture_map = {
|
||||
gif = true,
|
||||
}
|
||||
|
||||
function M.draw()
|
||||
function M.draw(unloaded_bufnr)
|
||||
local bufnr = view.get_bufnr()
|
||||
if not core.get_explorer() or not bufnr or not vim.api.nvim_buf_is_loaded(bufnr) then
|
||||
return
|
||||
@ -73,7 +73,7 @@ function M.draw()
|
||||
:configure_symlink_destination(M.config.symlink_destination)
|
||||
:configure_filter(live_filter.filter, live_filter.prefix)
|
||||
:build_header(view.is_root_folder_visible(core.get_cwd()))
|
||||
:build(core.get_explorer())
|
||||
:build(core.get_explorer(), unloaded_bufnr)
|
||||
:unwrap()
|
||||
end
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user