From 0b0e8cf85ab5fcb891b7cfd44c0c4908c0e1ef46 Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Mon, 24 Oct 2022 23:02:14 +0200 Subject: [PATCH] fix: return message id in vim.notify, so it can be used for replace if the view supports it. Fixes #109 --- lua/noice/source/notify.lua | 1 + lua/noice/view/backend/notify.lua | 14 +++++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/lua/noice/source/notify.lua b/lua/noice/source/notify.lua index 6bf1b34..24f1e1f 100644 --- a/lua/noice/source/notify.lua +++ b/lua/noice/source/notify.lua @@ -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 diff --git a/lua/noice/view/backend/notify.lua b/lua/noice/view/backend/notify.lua index e954d20..6e25ae7 100644 --- a/lua/noice/view/backend/notify.lua +++ b/lua/noice/view/backend/notify.lua @@ -25,6 +25,7 @@ local defaults = { ---@field buf? number ---@field notif table ---@field super NoiceView +---@field _notifs table ---@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,6 +128,9 @@ 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)), @@ -133,9 +138,16 @@ function NotifyView:_notify(msg) 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()