fix: highlight loaded buffers every time (#202)

This commit is contained in:
Zheng PiaoDan 2024-05-24 18:26:46 +08:00 committed by GitHub
parent 328452afcc
commit 1a05e58014
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -13,18 +13,7 @@ local EntryMaker = {}
---@param fs FrecencyFS ---@param fs FrecencyFS
---@return FrecencyEntryMaker ---@return FrecencyEntryMaker
EntryMaker.new = function(fs) EntryMaker.new = function(fs)
local self = setmetatable({ fs = fs, web_devicons = WebDevicons.new() }, { __index = EntryMaker }) return setmetatable({ fs = fs, web_devicons = WebDevicons.new() }, { __index = EntryMaker })
local loaded_bufnrs = vim.tbl_filter(function(v)
return vim.api.nvim_buf_is_loaded(v)
end, vim.api.nvim_list_bufs())
self.loaded = {}
for _, bufnr in ipairs(loaded_bufnrs) do
local bufname = vim.api.nvim_buf_get_name(bufnr)
if bufname then
self.loaded[bufname] = true
end
end
return self
end end
---@class FrecencyEntry ---@class FrecencyEntry
@ -57,6 +46,18 @@ function EntryMaker:create(filepath_formatter, workspace, workspace_tag)
items = self:width_items(workspace, workspace_tag), items = self:width_items(workspace, workspace_tag),
} }
-- set loaded buffers for highlight
self.loaded = {}
local loaded_bufnrs = vim.tbl_filter(function(v)
return vim.api.nvim_buf_is_loaded(v)
end, vim.api.nvim_list_bufs())
for _, bufnr in ipairs(loaded_bufnrs) do
local bufname = vim.api.nvim_buf_get_name(bufnr)
if bufname then
self.loaded[bufname] = true
end
end
return function(file) return function(file)
return { return {
filename = file.path, filename = file.path,