Skip to content

Commit

Permalink
perf: ignore events when setting buf options during render. Fixes #694
Browse files Browse the repository at this point in the history
  • Loading branch information
folke committed Jan 22, 2024
1 parent 8a8e129 commit bf67d70
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
15 changes: 13 additions & 2 deletions lua/noice/util/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,22 @@ function M.open(uri)
end
end

---@param fn fun():any
function M.ignore_events(fn)
local ei = vim.go.eventignore
vim.go.eventignore = "all"
local ret = fn()
vim.go.eventignore = ei
return ret
end

function M.tag(buf, tag)
local ft = vim.api.nvim_buf_get_option(buf, "filetype")
local ft = vim.bo[buf].filetype

if ft == "" then
vim.api.nvim_buf_set_option(buf, "filetype", "noice")
M.ignore_events(function()
vim.bo[buf].filetype = "noice"
end)
end

if Config.options.debug and vim.api.nvim_buf_get_name(buf) == "" then
Expand Down
4 changes: 3 additions & 1 deletion lua/noice/view/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,9 @@ function View:render(buf, opts)
local linenr = opts.offset or 1

if self._opts.buf_options then
require("nui.utils")._.set_buf_options(buf, self._opts.buf_options)
Util.ignore_events(function()
require("nui.utils")._.set_buf_options(buf, self._opts.buf_options)
end)
end

if self._opts.lang and not vim.b[buf].ts_highlight then
Expand Down

0 comments on commit bf67d70

Please sign in to comment.