base46/lua/base46/chadlights.lua
Nikita Rudenko a7592dcc1d Fix user highlights not updated on theme toggling
Lua copies tables by reference, which leads to permanent replacements of
named colors to their absolute values in user highlight table.
Thus, when theme is toggled or changed, user highlights are not updated,
cause they are stuck with absolute values.
This commit does two thigs:
 * Copy user highlight tables by value
 * Add missing hl_add update in chadlights.lua
2022-07-29 14:19:41 +03:00

49 lines
1.5 KiB
Lua

local merge_tb = require("base46").merge_tb
local ui = require("core.utils").load_config().ui
local highlights = {}
-- push hl_dir file names to table
local hl_files = vim.fn.stdpath "data" .. "/site/pack/packer/start/base46/lua/base46/integrations"
for _, file in ipairs(vim.fn.readdir(hl_files)) do
local integration = require("base46.integrations." .. vim.fn.fnamemodify(file, ":r"))
highlights = merge_tb(highlights, integration)
end
-- polish theme specific highlights
local polish_hl = require("base46").get_theme_tb "polish_hl"
if polish_hl then
highlights = merge_tb(highlights, polish_hl)
end
-- override user highlights if there are any
local user_hl_override = vim.deepcopy(ui.hl_override)
local user_hl_add = vim.deepcopy(ui.hl_add)
local user_highlights = merge_tb(user_hl_override, user_hl_add)
local colors = require("base46").get_theme_tb "base_30"
-- fg = "white" set by user becomes fg = colors["white"]
-- so no need for the user to import colors
for group, _ in pairs(user_highlights) do
for key, val in pairs(user_highlights[group]) do
if key == "fg" or key == "bg" then
if val:sub(1, 1) == "#" or val == "none" or val == "NONE" then
user_highlights[group][key] = val
else
user_highlights[group][key] = colors[val]
end
end
end
end
highlights = merge_tb(highlights, user_highlights)
-- local set_transparent = nvchad.load_config().ui.transparency
if vim.g.transparency then
highlights = merge_tb(highlights, require "base46.glassy")
end
return highlights