diff --git a/README.md b/README.md index 177de68..0d8b747 100644 --- a/README.md +++ b/README.md @@ -628,6 +628,7 @@ require("telescope").load_extension("noice") - `:Noice` or `:Noice history` shows the message history - `:Noice last` shows the last message in a popup +- `:Noice dismiss` dismiss all visible messages - `:Noice errors` shows the error messages in a split. Last errors on top - `:Noice disable` disables **Noice** - `:Noice enable` enables **Noice** diff --git a/lua/noice/commands.lua b/lua/noice/commands.lua index 46eee4c..6297b4c 100644 --- a/lua/noice/commands.lua +++ b/lua/noice/commands.lua @@ -5,6 +5,7 @@ local Manager = require("noice.message.manager") local Config = require("noice.config") local Util = require("noice.util") local Message = require("noice.message") +local Router = require("noice.message.router") ---@class NoiceCommand: NoiceRouteConfig ---@field filter_opts NoiceMessageOpts @@ -42,6 +43,9 @@ function M.setup() debug = function() Config.options.debug = not Config.options.debug end, + dismiss = function() + Router.dismiss() + end, log = function() vim.cmd.edit(Config.options.log) end, diff --git a/lua/noice/message/router.lua b/lua/noice/message/router.lua index 19552a9..5b324ae 100644 --- a/lua/noice/message/router.lua +++ b/lua/noice/message/router.lua @@ -141,6 +141,16 @@ function M.get_views() return views end +function M.dismiss() + Manager.clear() + local views = M.get_views() + for view, _ in pairs(views) do + view:dismiss() + view:display() + end + M.update() +end + function M.update() if Util.is_exiting() then return diff --git a/lua/noice/view/backend/mini.lua b/lua/noice/view/backend/mini.lua index aeb43a9..b898875 100644 --- a/lua/noice/view/backend/mini.lua +++ b/lua/noice/view/backend/mini.lua @@ -72,6 +72,12 @@ function MiniView:show() self:update() end +function MiniView:dismiss() + self:clear() + self.active = {} + self:update() +end + function MiniView:update() local active = vim.tbl_values(self.active) table.sort( diff --git a/lua/noice/view/init.lua b/lua/noice/view/init.lua index 699dc2c..94b2449 100644 --- a/lua/noice/view/init.lua +++ b/lua/noice/view/init.lua @@ -110,6 +110,10 @@ function View:clear() self._route_opts = {} end +function View:dismiss() + self:clear() +end + function View:check_options() ---@type NoiceViewOptions local old = vim.deepcopy(self._opts)