From 9bcac87453214ef1d2ae14c5830083c57d7a6340 Mon Sep 17 00:00:00 2001 From: Max Date: Tue, 5 Nov 2024 15:12:21 +0100 Subject: [PATCH] feat(highlights): work with switching colorscheme fixes https://github.com/max397574/care.nvim/issues/131 --- lua/care/highlights.lua | 66 ++++++++++++++++++++++++++++------------- 1 file changed, 45 insertions(+), 21 deletions(-) diff --git a/lua/care/highlights.lua b/lua/care/highlights.lua index 93d2fea..b64a9f3 100644 --- a/lua/care/highlights.lua +++ b/lua/care/highlights.lua @@ -57,25 +57,49 @@ local kinds = { TypeParameter = "@type", } -for name, group in pairs(kinds) do - local highlights = vim.api.nvim_get_hl(0, { name = group, link = false }) - local normal_float = vim.api.nvim_get_hl(0, { name = "NormalFloat" }) - local normal = vim.api.nvim_get_hl(0, { name = "Normal" }) - local fg = string.format("#%06x", highlights.fg or normal_float.fg or normal.fg) - hl(string.format("@care.type.%s", name), { link = group, default = true }) - hl(string.format("@care.type.fg.%s", name), { fg = fg, default = true }) - hl( - string.format("@care.type.blended.%s", name), - { fg = fg, bg = blend_colors(fg, string.format("#%06x", normal_float.bg or normal.bg), 0.15), default = true } - ) -end +vim.api.nvim_create_autocmd("ColorSchemePre", { + callback = function() + for name, _ in pairs(kinds) do + hl(string.format("@care.type.%s", name), {}) + hl(string.format("@care.type.fg.%s", name), {}) + hl(string.format("@care.type.blended.%s", name), {}) + end + hl("@care", {}) + hl("@care.type", {}) + hl("@care.selected", {}) + hl("@care.match", {}) + hl("@care.menu", {}) + hl("@care.scrollbar", {}) + hl("@care.entry", {}) + hl("@care.ghost_text", {}) + hl("@care.scrollbar.thumb", {}) + end, +}) + +vim.api.nvim_create_autocmd("ColorScheme", { + callback = function() + for name, group in pairs(kinds) do + local highlights = vim.api.nvim_get_hl(0, { name = group, link = false }) + local normal_float = vim.api.nvim_get_hl(0, { name = "NormalFloat" }) + local normal = vim.api.nvim_get_hl(0, { name = "Normal" }) + local fg = string.format("#%06x", highlights.fg or normal_float.fg or normal.fg) + hl(string.format("@care.type.%s", name), { link = group, default = true }) + hl(string.format("@care.type.fg.%s", name), { fg = fg, default = true }) + hl(string.format("@care.type.blended.%s", name), { + fg = fg, + bg = blend_colors(fg, string.format("#%06x", normal_float.bg or normal.bg), 0.15), + default = true, + }) + end -hl("@care", { link = "Normal", default = true }) -hl("@care.type", { link = "Normal", default = true }) -hl("@care.selected", { link = "Visual", default = true }) -hl("@care.match", { link = "Special", default = true }) -hl("@care.menu", { link = "NormalFloat", default = true }) -hl("@care.scrollbar", { link = "PmenuSbar", default = true }) -hl("@care.entry", { italic = true, default = true }) -hl("@care.ghost_text", { link = "Comment", default = true }) -hl("@care.scrollbar.thumb", { link = "PmenuSbar", default = true }) + hl("@care", { link = "Normal", default = true }) + hl("@care.type", { link = "Normal", default = true }) + hl("@care.selected", { link = "Visual", default = true }) + hl("@care.match", { link = "Special", default = true }) + hl("@care.menu", { link = "NormalFloat", default = true }) + hl("@care.scrollbar", { link = "PmenuSbar", default = true }) + hl("@care.entry", { italic = true, default = true }) + hl("@care.ghost_text", { link = "Comment", default = true }) + hl("@care.scrollbar.thumb", { link = "PmenuSbar", default = true }) + end, +})