Skip to content

Commit

Permalink
fix(util): simplify set_highlight and fix settings being cleared
Browse files Browse the repository at this point in the history
This function was doing too much unnecessary things and was resetting
user highlights tables to nil as well as unnecessarily trying to merge
tables multiple times this changes should also make this function much
more performant.
  • Loading branch information
A-Lamia committed Jul 14, 2023
1 parent a182b19 commit 719a59b
Showing 1 changed file with 2 additions and 17 deletions.
19 changes: 2 additions & 17 deletions lua/astrotheme/lib/util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -55,25 +55,10 @@ function M.set_palettes(opts)
end

function M.set_highlights(opts, highlights, theme)
local opts_hl_glob = opts.highlights.global
if opts_hl_glob.modify_hl_groups then
opts_hl_glob.modify_hl_groups(highlights, C)
opts_hl_glob.modify_hl_groups = nil
end

highlights = vim.tbl_deep_extend("force", highlights, opts_hl_glob)
pcall(opts.highlights.global.modify_hl_groups, highlights, C)
pcall(opts.highlights[theme].modify_hl_groups, highlights, C)

local opts_hl = opts.highlights[theme]
if opts_hl.modify_hl_groups then
opts_hl.modify_hl_groups(highlights, C)
opts_hl.modify_hl_groups = nil
end

highlights = vim.tbl_deep_extend("force", highlights, opts_hl)
for group, spec in pairs(highlights) do
for key, value in pairs(spec) do
if type(value) == table then spec[key] = value:toHex() end
end
vim.api.nvim_set_hl(0, group, spec)
end
end
Expand Down

0 comments on commit 719a59b

Please sign in to comment.