Skip to content

Commit

Permalink
fix: ensure hlgroup cache is always cleared on ColorScheme
Browse files Browse the repository at this point in the history
  • Loading branch information
willothy committed Dec 23, 2023
1 parent 321afcd commit 90ac470
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
11 changes: 11 additions & 0 deletions lua/cokeline/augroups.lua
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,17 @@ local setup = function()
local autocmd, augroup =
vim.api.nvim_create_autocmd, vim.api.nvim_create_augroup

-- Invalidate the cache on colorscheme change
autocmd("ColorScheme", {
pattern = "*",
-- NOTE: For some reason, the autocmd does not consistently trigger without this
nested = true,
group = augroup("cokeline_color_cache", { clear = true }),
callback = function()
require("cokeline.hlgroups")._cache_clear()
end,
})

autocmd({ "VimEnter", "BufAdd" }, {
group = augroup("cokeline_toggle", { clear = true }),
callback = function()
Expand Down
15 changes: 5 additions & 10 deletions lua/cokeline/hlgroups.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,11 @@ local cache = {
groups = {},
}

-- Invalidate the cache on colorscheme change
vim.api.nvim_create_autocmd("Colorscheme", {
group = vim.api.nvim_create_augroup(
"cokeline_color_cache",
{ clear = true }
),
callback = function()
cache.groups = {}
end,
})
---Clears the hlgroup cache.
---@private
function M._cache_clear()
cache.groups = {}
end

---@param rgb integer
---@return string hex
Expand Down

0 comments on commit 90ac470

Please sign in to comment.