feat(toggle): move toggle notifs to toggle function

This commit is contained in:
Folke Lemaitre 2024-07-17 15:06:45 +02:00
parent d263cf5dd1
commit c1b76ee235
No known key found for this signature in database
GPG key ID: 41F8B1FBACAE2040

View file

@ -12,9 +12,15 @@ local M = {}
---@param toggle lazyvim.Toggle ---@param toggle lazyvim.Toggle
function M.wrap(toggle) function M.wrap(toggle)
return setmetatable(toggle, { return setmetatable(toggle, {
__call = function(t) __call = function()
t.set(not t.get()) toggle.set(not toggle.get())
return t.get() local state = toggle.get()
if state then
LazyVim.info("Enabled " .. toggle.name, { title = toggle.name })
else
LazyVim.warn("Disabled " .. toggle.name, { title = toggle.name })
end
return state
end, end,
}) --[[@as lazyvim.Toggle.wrap]] }) --[[@as lazyvim.Toggle.wrap]]
end end
@ -24,11 +30,7 @@ end
function M.map(lhs, toggle) function M.map(lhs, toggle)
local t = M.wrap(toggle) local t = M.wrap(toggle)
LazyVim.safe_keymap_set("n", lhs, function() LazyVim.safe_keymap_set("n", lhs, function()
if t() then t()
LazyVim.info("Enabled " .. toggle.name, { title = toggle.name })
else
LazyVim.warn("Disabled " .. toggle.name, { title = toggle.name })
end
end, { desc = "Toggle " .. toggle.name }) end, { desc = "Toggle " .. toggle.name })
M.wk(lhs, toggle) M.wk(lhs, toggle)
end end