mirror of
https://github.com/folke/snacks.nvim
synced 2025-08-04 10:49:08 +00:00
feat(notifier) added opts.filter
to filter out unwanted notifications. Closes #431
This commit is contained in:
parent
8d491a0975
commit
2b38a19dc9
1 changed files with 6 additions and 2 deletions
|
@ -108,6 +108,7 @@ Snacks.config.style("notification_history", {
|
|||
---@class snacks.notifier.Config
|
||||
---@field enabled? boolean
|
||||
---@field keep? fun(notif: snacks.notifier.Notif): boolean # global keep function
|
||||
---@field filter? fun(notif: snacks.notifier.Notif): boolean # filter our unwanted notifications (return false to hide)
|
||||
local defaults = {
|
||||
timeout = 3000, -- default timeout in ms
|
||||
width = { min = 40, max = 0.4 },
|
||||
|
@ -399,9 +400,12 @@ function N:add(opts)
|
|||
notif.dirty = true
|
||||
end
|
||||
self.sorted = nil
|
||||
if numlevel(notif.level) >= numlevel(self.opts.level) then
|
||||
self.queue[notif.id] = notif
|
||||
local want = numlevel(notif.level) >= numlevel(self.opts.level)
|
||||
want = want and (not self.opts.filter or self.opts.filter(notif))
|
||||
if not want then
|
||||
return notif.id
|
||||
end
|
||||
self.queue[notif.id] = notif
|
||||
if opts.history ~= false then
|
||||
self.history[notif.id] = notif
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue