Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed highlight-opened-files doesn't automatically refresh #1827

Merged
merged 1 commit into from
Dec 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lua/nvim-tree.lua
Original file line number Diff line number Diff line change
Expand Up @@ -356,15 +356,15 @@ 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,
})

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,
Expand Down
2 changes: 1 addition & 1 deletion lua/nvim-tree/actions/reloaders/reloaders.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 9 additions & 7 deletions lua/nvim-tree/renderer/builder.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions lua/nvim-tree/renderer/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down