Skip to content

Commit

Permalink
feat: added Noice dismiss to hide all visible messages. Fixes folke…
Browse files Browse the repository at this point in the history
  • Loading branch information
folke authored and willothy committed Aug 19, 2023
1 parent f3ef222 commit 3bfb563
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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**
Expand Down
4 changes: 4 additions & 0 deletions lua/noice/commands.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
10 changes: 10 additions & 0 deletions lua/noice/message/router.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions lua/noice/view/backend/mini.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
4 changes: 4 additions & 0 deletions lua/noice/view/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 3bfb563

Please sign in to comment.