mirror of
https://github.com/LazyVim/LazyVim.git
synced 2025-07-06 23:44:41 +02:00
refactor: option names
This commit is contained in:
parent
4d9407dc22
commit
24918c2565
2 changed files with 14 additions and 22 deletions
|
@ -117,14 +117,14 @@ map("n", "[w", diagnostic_goto(false, "WARN"), { desc = "Prev Warning" })
|
|||
-- toggle options
|
||||
LazyVim.toggle.map("<leader>uf", LazyVim.toggle.format())
|
||||
LazyVim.toggle.map("<leader>uF", LazyVim.toggle.format(true))
|
||||
LazyVim.toggle.map("<leader>us", LazyVim.toggle("spell"))
|
||||
LazyVim.toggle.map("<leader>uw", LazyVim.toggle("wrap"))
|
||||
LazyVim.toggle.map("<leader>uL", LazyVim.toggle("relativenumber"))
|
||||
LazyVim.toggle.map("<leader>us", LazyVim.toggle("spell", { name = "Spelling" }))
|
||||
LazyVim.toggle.map("<leader>uw", LazyVim.toggle("wrap", { name = "Wrap" }))
|
||||
LazyVim.toggle.map("<leader>uL", LazyVim.toggle("relativenumber", { name = "Relative Number" }))
|
||||
LazyVim.toggle.map("<leader>ud", LazyVim.toggle.diagnostics)
|
||||
LazyVim.toggle.map("<leader>ul", LazyVim.toggle.number)
|
||||
LazyVim.toggle.map("<leader>uc", LazyVim.toggle("conceallevel", { 0, vim.o.conceallevel > 0 and vim.o.conceallevel or 2 }))
|
||||
LazyVim.toggle.map( "<leader>uc", LazyVim.toggle("conceallevel", { values = { 0, vim.o.conceallevel > 0 and vim.o.conceallevel or 2 } }))
|
||||
LazyVim.toggle.map("<leader>uT", LazyVim.toggle.treesitter)
|
||||
LazyVim.toggle.map("<leader>ub", LazyVim.toggle("background", { "light", "dark" }))
|
||||
LazyVim.toggle.map("<leader>ub", LazyVim.toggle("background", { values = { "light", "dark" }, name = "Background" }))
|
||||
if vim.lsp.inlay_hint then
|
||||
LazyVim.toggle.map("<leader>uh", LazyVim.toggle.inlay_hints)
|
||||
end
|
||||
|
|
|
@ -74,28 +74,20 @@ function M.format(buf)
|
|||
return ret
|
||||
end
|
||||
|
||||
---@param values? {[1]:any, [2]:any}
|
||||
function M.option(option, values)
|
||||
---@param opts? {values?: {[1]:any, [2]:any}, name?: string}
|
||||
function M.option(option, opts)
|
||||
opts = opts or {}
|
||||
local name = opts.name or option
|
||||
local on = opts.values and opts.values[2] or true
|
||||
local off = opts.values and opts.values[1] or false
|
||||
---@type lazyvim.Toggle
|
||||
local ret = {
|
||||
name = option,
|
||||
name = name,
|
||||
get = function()
|
||||
if values then
|
||||
return vim.opt_local[option]:get() == values[2]
|
||||
end
|
||||
return vim.opt_local[option]:get()
|
||||
return vim.opt_local[option]:get() == on
|
||||
end,
|
||||
set = function(state)
|
||||
if values then
|
||||
if state then
|
||||
vim.opt_local[option] = values[2]
|
||||
else
|
||||
vim.opt_local[option] = values[1]
|
||||
end
|
||||
else
|
||||
---@diagnostic disable-next-line: no-unknown
|
||||
vim.opt_local[option] = state
|
||||
end
|
||||
vim.opt_local[option] = state and on or off
|
||||
end,
|
||||
}
|
||||
return ret
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue