mirror of
https://github.com/LazyVim/LazyVim.git
synced 2025-06-24 17:58:51 +02:00
fix(hipatterns): reset hl groups when colorscheme changes
This commit is contained in:
parent
5eccaeb992
commit
b7a925904e
1 changed files with 12 additions and 7 deletions
|
@ -19,22 +19,27 @@ M.plugin = {
|
||||||
config = function(_, opts)
|
config = function(_, opts)
|
||||||
if opts.tailwind then
|
if opts.tailwind then
|
||||||
local tailwind_ft = { "typescriptreact", "javascriptreact", "css", "javascript", "typescript", "html" }
|
local tailwind_ft = { "typescriptreact", "javascriptreact", "css", "javascript", "typescript", "html" }
|
||||||
|
-- reset hl groups when colorscheme changes
|
||||||
|
vim.api.nvim_create_autocmd("ColorScheme", {
|
||||||
|
callback = function()
|
||||||
|
M.hl = {}
|
||||||
|
end,
|
||||||
|
})
|
||||||
opts.highlighters.tailwind = {
|
opts.highlighters.tailwind = {
|
||||||
pattern = function()
|
pattern = function()
|
||||||
if not vim.tbl_contains(tailwind_ft, vim.bo.filetype) then
|
return vim.tbl_contains(tailwind_ft, vim.bo.filetype) and "%f[%w:-]()[%w:-]+%-[a-z%-]+%-%d+()%f[^%w:-]"
|
||||||
return
|
|
||||||
end
|
|
||||||
return "%f[%w:-]()[%w:-]+%-[a-z%-]+%-%d+()%f[^%w:-]"
|
|
||||||
end,
|
end,
|
||||||
group = function(_, match)
|
group = function(_, match)
|
||||||
---@type string,string
|
---@type string, number
|
||||||
local color, shade = match:match("[%w-]+%-([a-z%-]+)%-(%d+)")
|
local color, shade = match:match("[%w-]+%-([a-z%-]+)%-(%d+)")
|
||||||
local bg = vim.tbl_get(M.colors, color, tonumber(shade))
|
shade = assert(tonumber(shade))
|
||||||
|
local bg = vim.tbl_get(M.colors, color, shade)
|
||||||
if bg then
|
if bg then
|
||||||
local hl = "MiniHipatternsTailwind" .. color .. shade
|
local hl = "MiniHipatternsTailwind" .. color .. shade
|
||||||
if not M.hl[hl] then
|
if not M.hl[hl] then
|
||||||
M.hl[hl] = true
|
M.hl[hl] = true
|
||||||
local fg = vim.tbl_get(M.colors, color, tonumber(shade) >= 500 and 100 or 900)
|
local bg_shade = shade == 500 and 950 or shade < 500 and 900 or 100
|
||||||
|
local fg = vim.tbl_get(M.colors, color, bg_shade)
|
||||||
vim.api.nvim_set_hl(0, hl, { bg = "#" .. bg, fg = "#" .. fg })
|
vim.api.nvim_set_hl(0, hl, { bg = "#" .. bg, fg = "#" .. fg })
|
||||||
end
|
end
|
||||||
return hl
|
return hl
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue