fix: resolve lazy.nvim loading issue and theme priority
This commit is contained in:
+10
-2
@@ -169,8 +169,16 @@ local M = {}
|
|||||||
---@return { theme: ThemeColors, palette: PaletteColors}
|
---@return { theme: ThemeColors, palette: PaletteColors}
|
||||||
function M.setup(opts)
|
function M.setup(opts)
|
||||||
opts = opts or {}
|
opts = opts or {}
|
||||||
local override_colors = opts.colors or require("kanso").config.colors
|
local kanso = require("kanso")
|
||||||
local theme = opts.theme or require("kanso")._CURRENT_THEME -- WARN: this fails if called before kanso.load()
|
local override_colors = opts.colors or kanso.config.colors
|
||||||
|
local theme = opts.theme or kanso._CURRENT_THEME
|
||||||
|
|
||||||
|
-- Fallback: if _CURRENT_THEME is not set yet, try to determine theme from config
|
||||||
|
if not theme then
|
||||||
|
theme = kanso.config.background[vim.o.background] or kanso.config.theme or "ink"
|
||||||
|
-- Store it for future use
|
||||||
|
kanso._CURRENT_THEME = theme
|
||||||
|
end
|
||||||
|
|
||||||
if not theme then
|
if not theme then
|
||||||
error(
|
error(
|
||||||
|
|||||||
+24
-2
@@ -32,6 +32,9 @@ M.config = {
|
|||||||
compile = false,
|
compile = false,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
-- Store default config for comparison
|
||||||
|
M._DEFAULT_CONFIG = vim.deepcopy(M.config)
|
||||||
|
|
||||||
local function check_config(_)
|
local function check_config(_)
|
||||||
local err
|
local err
|
||||||
return not err
|
return not err
|
||||||
@@ -57,9 +60,28 @@ function M.load(theme)
|
|||||||
M._EXPLICIT_THEME = theme
|
M._EXPLICIT_THEME = theme
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Use explicit theme if set, otherwise fall back to background-based selection
|
-- Priority order for theme selection:
|
||||||
theme = M._EXPLICIT_THEME or M.config.background[vim.o.background] or M.config.theme
|
-- 1. Explicitly loaded theme variant (e.g., :colorscheme kanso-zen)
|
||||||
|
-- 2. Theme specified in config if different from default
|
||||||
|
-- 3. Background-based selection if available
|
||||||
|
-- 4. Fallback to config theme
|
||||||
|
if M._EXPLICIT_THEME then
|
||||||
|
theme = M._EXPLICIT_THEME
|
||||||
|
elseif M.config.theme ~= M._DEFAULT_CONFIG.theme then
|
||||||
|
-- User explicitly changed theme in config
|
||||||
|
theme = M.config.theme
|
||||||
|
elseif M.config.background and M.config.background[vim.o.background] then
|
||||||
|
-- Use background-based selection
|
||||||
|
theme = M.config.background[vim.o.background]
|
||||||
|
else
|
||||||
|
-- Use config theme (whether default or user-specified)
|
||||||
|
theme = M.config.theme
|
||||||
|
end
|
||||||
M._CURRENT_THEME = theme
|
M._CURRENT_THEME = theme
|
||||||
|
|
||||||
|
-- Ensure the theme is available to colors module before any require() calls
|
||||||
|
-- This prevents circular dependency issues when loading within lazy.nvim
|
||||||
|
package.loaded["kanso"] = M
|
||||||
|
|
||||||
if vim.g.colors_name then
|
if vim.g.colors_name then
|
||||||
vim.cmd("hi clear")
|
vim.cmd("hi clear")
|
||||||
|
|||||||
Reference in New Issue
Block a user