Skip to content

Commit 7673bbe

Browse files
committed
fix: correctly maintain background setting when changing colorscheme styles
1 parent bc7e440 commit 7673bbe

File tree

2 files changed

+22
-11
lines changed

2 files changed

+22
-11
lines changed

lua/astrotheme/init.lua

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,32 @@ local M = { config = {} }
1313

1414
local util = require "astrotheme.lib.util"
1515

16+
local style_background = {
17+
astrodark = "dark",
18+
astrolight = "light",
19+
astromars = "dark",
20+
astrojupiter = "light",
21+
}
22+
23+
local invert_style = {
24+
astrodark = "astrolight",
25+
astrolight = "astrodark",
26+
astromars = "astrojupiter",
27+
astrojupiter = "astromars",
28+
}
29+
1630
--- Load a specific theme given a palette name
1731
---@param theme? string
1832
function M.load(theme)
19-
if
20-
not theme
21-
or (
22-
theme == M.config.palette
23-
and vim.o.background ~= (M.config.palette == M.config.background["light"] and "light" or "dark")
24-
)
25-
then
33+
if not theme then
2634
theme = M.config.background[vim.o.background]
35+
elseif theme == M.config.palette then
36+
if vim.o.background ~= style_background[theme] then theme = invert_style[theme] end
37+
else
38+
vim.o.background = style_background[theme]
2739
end
2840
M.config.palette = theme
29-
util.reload(M.config, theme)
41+
util.reload(M.config)
3042

3143
local colors = util.set_palettes(M.config)
3244

lua/astrotheme/lib/util.lua

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,11 @@ local M = {}
1010

1111
--- Reload a given theme
1212
---@param opts AstroThemeOpts
13-
---@param theme string
14-
function M.reload(opts, theme)
13+
function M.reload(opts)
1514
if vim.g.colors_name then vim.cmd.highlight "clear" end
1615
if vim.fn.exists "syntax_on" then vim.cmd.syntax "reset" end
1716
vim.o.termguicolors = opts.termguicolors
18-
vim.g.colors_name = theme
17+
vim.g.colors_name = opts.palette
1918
end
2019

2120
--- Reload a module

0 commit comments

Comments
 (0)