fix(win): allow resolving nil window option values. Fixes #179

This commit is contained in:
Folke Lemaitre 2024-12-01 17:19:12 +01:00
parent d023bf7034
commit 0043fa9ee1
No known key found for this signature in database
GPG key ID: 41F8B1FBACAE2040

View file

@ -143,20 +143,26 @@ vim.api.nvim_create_autocmd("ColorScheme", {
local id = 0
---@private
---@param ... snacks.win.Config|string
---@param ...? snacks.win.Config|string
---@return snacks.win.Config
function M.resolve(...)
local done = {} ---@type string[]
local done = {} ---@type table<string, boolean>
local merge = {} ---@type snacks.win.Config[]
local stack = { ... }
local stack = {}
for i = 1, select("#", ...) do
local next = select(i, ...) ---@type snacks.win.Config|string?
if next then
table.insert(stack, next)
end
end
while #stack > 0 do
local next = table.remove(stack)
next = type(next) == "table" and next or vim.deepcopy(Snacks.config.styles[next])
next = type(next) == "string" and Snacks.config.styles[next] or next
---@cast next snacks.win.Config?
if next then
if next and type(next) == "table" then
table.insert(merge, 1, next)
if next.style and not vim.tbl_contains(done, next.style) then
table.insert(done, next.style)
if next.style and not done[next.style] then
done[next.style] = true
table.insert(stack, next.style)
end
end