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
|
---@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
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue