Skip to content

Commit

Permalink
fix: return message id in vim.notify, so it can be used for replace i…
Browse files Browse the repository at this point in the history
…f the view supports it. Fixes #109
  • Loading branch information
folke committed Oct 24, 2022
1 parent cc8c07a commit 0b0e8cf
Showing 2 changed files with 14 additions and 1 deletion.
1 change: 1 addition & 0 deletions lua/noice/source/notify.lua
Original file line number Diff line number Diff line change
@@ -60,6 +60,7 @@ function M.notify(msg, level, opts)
if Util.is_blocking() then
Router.update()
end
return { id = message.id }
end

return M
14 changes: 13 additions & 1 deletion lua/noice/view/backend/notify.lua
Original file line number Diff line number Diff line change
@@ -25,6 +25,7 @@ local defaults = {
---@field buf? number
---@field notif table<NotifyInstance, notify.Record>
---@field super NoiceView
---@field _notifs table<number, any>
---@diagnostic disable-next-line: undefined-field
local NotifyView = View:extend("NotifyView")

@@ -51,6 +52,7 @@ end
function NotifyView:init(opts)
NotifyView.super.init(self, opts)
self.notif = {}
self._notifs = {}
end

function NotifyView:is_available()
@@ -126,16 +128,26 @@ function NotifyView:_notify(msg)
end,
on_close = function()
self.notif[instance] = nil
for _, m in ipairs(msg.messages) do
self._notifs[m.id] = nil
end
self.win = nil
end,
render = Util.protect(self:notify_render(msg.messages)),
}

if msg.opts then
opts = vim.tbl_deep_extend("force", opts, msg.opts)
if type(msg.opts.replace) == "table" then
opts.replace = self._notifs[msg.opts.replace.id]
end
end

self.notif[instance] = instance.notify(msg.content, level, opts)
local id = instance.notify(msg.content, level, opts)
self.notif[instance] = id
for _, m in ipairs(msg.messages) do
self._notifs[m.id] = id
end
end

function NotifyView:show()

0 comments on commit 0b0e8cf

Please sign in to comment.