Skip to content

Commit

Permalink
fix: correctly maintain background setting when changing colorschem…
Browse files Browse the repository at this point in the history
…e styles
  • Loading branch information
mehalter committed Sep 26, 2024
1 parent bc7e440 commit 7673bbe
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
28 changes: 20 additions & 8 deletions lua/astrotheme/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,32 @@ local M = { config = {} }

local util = require "astrotheme.lib.util"

local style_background = {
astrodark = "dark",
astrolight = "light",
astromars = "dark",
astrojupiter = "light",
}

local invert_style = {
astrodark = "astrolight",
astrolight = "astrodark",
astromars = "astrojupiter",
astrojupiter = "astromars",
}

--- Load a specific theme given a palette name
---@param theme? string
function M.load(theme)
if
not theme
or (
theme == M.config.palette
and vim.o.background ~= (M.config.palette == M.config.background["light"] and "light" or "dark")
)
then
if not theme then
theme = M.config.background[vim.o.background]
elseif theme == M.config.palette then
if vim.o.background ~= style_background[theme] then theme = invert_style[theme] end
else
vim.o.background = style_background[theme]
end
M.config.palette = theme
util.reload(M.config, theme)
util.reload(M.config)

local colors = util.set_palettes(M.config)

Expand Down
5 changes: 2 additions & 3 deletions lua/astrotheme/lib/util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@ local M = {}

--- Reload a given theme
---@param opts AstroThemeOpts
---@param theme string
function M.reload(opts, theme)
function M.reload(opts)
if vim.g.colors_name then vim.cmd.highlight "clear" end
if vim.fn.exists "syntax_on" then vim.cmd.syntax "reset" end
vim.o.termguicolors = opts.termguicolors
vim.g.colors_name = theme
vim.g.colors_name = opts.palette
end

--- Reload a module
Expand Down

0 comments on commit 7673bbe

Please sign in to comment.