mirror of
https://github.com/LazyVim/LazyVim.git
synced 2025-06-21 16:39:06 +02:00
fix(toggle): safe toggle get
This commit is contained in:
parent
0d561a3226
commit
c8ab5d7554
1 changed files with 9 additions and 2 deletions
|
@ -39,14 +39,21 @@ function M.wk(lhs, toggle)
|
||||||
if not LazyVim.has("which-key.nvim") then
|
if not LazyVim.has("which-key.nvim") then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
local function safe_get()
|
||||||
|
local ok, enabled = pcall(toggle.get)
|
||||||
|
if not ok then
|
||||||
|
LazyVim.error({ "Failed to get toggle state for **" .. toggle.name .. "**:\n", enabled }, { once = true })
|
||||||
|
end
|
||||||
|
return enabled
|
||||||
|
end
|
||||||
require("which-key").add({
|
require("which-key").add({
|
||||||
{
|
{
|
||||||
lhs,
|
lhs,
|
||||||
icon = function()
|
icon = function()
|
||||||
return toggle.get() and { icon = " ", color = "green" } or { icon = " ", color = "yellow" }
|
return safe_get() and { icon = " ", color = "green" } or { icon = " ", color = "yellow" }
|
||||||
end,
|
end,
|
||||||
desc = function()
|
desc = function()
|
||||||
return (toggle.get() and "Disable " or "Enable ") .. toggle.name
|
return (safe_get() and "Disable " or "Enable ") .. toggle.name
|
||||||
end,
|
end,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue