mirror of
https://github.com/LazyVim/LazyVim.git
synced 2025-06-21 16:39:06 +02:00
feat(toggle): move toggle notifs to toggle function
This commit is contained in:
parent
d263cf5dd1
commit
c1b76ee235
1 changed files with 10 additions and 8 deletions
|
@ -12,9 +12,15 @@ local M = {}
|
|||
---@param toggle lazyvim.Toggle
|
||||
function M.wrap(toggle)
|
||||
return setmetatable(toggle, {
|
||||
__call = function(t)
|
||||
t.set(not t.get())
|
||||
return t.get()
|
||||
__call = function()
|
||||
toggle.set(not toggle.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,
|
||||
}) --[[@as lazyvim.Toggle.wrap]]
|
||||
end
|
||||
|
@ -24,11 +30,7 @@ end
|
|||
function M.map(lhs, toggle)
|
||||
local t = M.wrap(toggle)
|
||||
LazyVim.safe_keymap_set("n", lhs, function()
|
||||
if t() then
|
||||
LazyVim.info("Enabled " .. toggle.name, { title = toggle.name })
|
||||
else
|
||||
LazyVim.warn("Disabled " .. toggle.name, { title = toggle.name })
|
||||
end
|
||||
t()
|
||||
end, { desc = "Toggle " .. toggle.name })
|
||||
M.wk(lhs, toggle)
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue