feat(notifier): added backward compatibility for nvim-notify's replace option

This commit is contained in:
Folke Lemaitre 2024-11-09 14:44:48 +01:00
parent 7e6ea65f5f
commit 9b9777ec3b
No known key found for this signature in database
GPG key ID: 41F8B1FBACAE2040

View file

@ -307,8 +307,15 @@ function N:add(opts)
local now = ts()
local notif = vim.deepcopy(opts) --[[@as snacks.notifier.Notif]]
notif.msg = notif.msg or ""
-- FIXME: normalize title, icon, etc to remove newlines
notif.title = notif.title or ""
-- NOTE: support nvim-notify style replace
---@diagnostic disable-next-line: undefined-field
if not notif.id and notif.replace then
---@diagnostic disable-next-line: undefined-field
notif.id = type(notif.replace) == "table" and notif.replace.id or notif.replace
end
notif.title = (notif.title or ""):gsub("\n", " ")
notif.id = notif.id or next_id()
notif.level = normlevel(notif.level)
notif.icon = notif.icon or self.opts.icons[notif.level]