mirror of
https://github.com/LazyVim/LazyVim.git
synced 2025-06-27 19:28:59 +02:00
feat(notify): delay notifs till replaced or at most 500ms to prevent more prompts
This commit is contained in:
parent
3dd367caac
commit
701337fac8
4 changed files with 52 additions and 10 deletions
|
@ -128,6 +128,20 @@ function M.load(name)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
M.did_init = false
|
||||||
|
function M.init()
|
||||||
|
if not M.did_init then
|
||||||
|
M.did_init = true
|
||||||
|
-- delay notifications till vim.notify was replaced or after 500ms
|
||||||
|
require("lazyvim.util").lazy_notify()
|
||||||
|
|
||||||
|
-- load options here, before lazy init while sourcing plugin modules
|
||||||
|
-- this is needed to make sure options will be correctly applied
|
||||||
|
-- after installing missing plugins
|
||||||
|
require("lazyvim.config").load("options")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
setmetatable(M, {
|
setmetatable(M, {
|
||||||
__index = function(_, key)
|
__index = function(_, key)
|
||||||
if options == nil then
|
if options == nil then
|
||||||
|
|
|
@ -1,6 +1,3 @@
|
||||||
-- load options here, before lazy init while sourcing plugin modules
|
require("lazyvim.config").init()
|
||||||
-- this is needed to make sure options will be correctly applied
|
|
||||||
-- after installing missing plugins
|
|
||||||
require("lazyvim.config").load("options")
|
|
||||||
|
|
||||||
return {}
|
return {}
|
||||||
|
|
|
@ -20,12 +20,6 @@ return {
|
||||||
return math.floor(vim.o.columns * 0.75)
|
return math.floor(vim.o.columns * 0.75)
|
||||||
end,
|
end,
|
||||||
},
|
},
|
||||||
init = function()
|
|
||||||
-- lazy-load notify here. Will be overriden by Noice when it loads
|
|
||||||
vim.notify = function(...)
|
|
||||||
return require("notify").notify(...)
|
|
||||||
end
|
|
||||||
end,
|
|
||||||
},
|
},
|
||||||
|
|
||||||
-- better vim.ui
|
-- better vim.ui
|
||||||
|
|
|
@ -125,4 +125,41 @@ function M.deprecate(old, new)
|
||||||
Util.warn(("`%s` is deprecated. Please use `%s` instead"):format(old, new), { title = "LazyVim" })
|
Util.warn(("`%s` is deprecated. Please use `%s` instead"):format(old, new), { title = "LazyVim" })
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- delay notifications till vim.notify was replaced or after 500ms
|
||||||
|
function M.lazy_notify()
|
||||||
|
local notifs = {}
|
||||||
|
local function temp(...)
|
||||||
|
table.insert(notifs, vim.F.pack_len(...))
|
||||||
|
end
|
||||||
|
|
||||||
|
vim.notify = temp
|
||||||
|
local orig = vim.notify
|
||||||
|
|
||||||
|
local timer = vim.loop.new_timer()
|
||||||
|
local check = vim.loop.new_check()
|
||||||
|
|
||||||
|
local replay = function()
|
||||||
|
timer:stop()
|
||||||
|
check:stop()
|
||||||
|
if vim.notify == temp then
|
||||||
|
vim.notify = orig -- put back the original notify if needed
|
||||||
|
end
|
||||||
|
vim.schedule(function()
|
||||||
|
---@diagnostic disable-next-line: no-unknown
|
||||||
|
for _, notif in ipairs(notifs) do
|
||||||
|
vim.notify(vim.F.unpack_len(notif))
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- wait till vim.notify has been replaced
|
||||||
|
check:start(function()
|
||||||
|
if vim.notify ~= temp then
|
||||||
|
replay()
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
-- or if it took more than 500ms, then something went wrong
|
||||||
|
timer:start(500, 0, replay)
|
||||||
|
end
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue