mirror of
https://github.com/folke/snacks.nvim
synced 2025-08-04 02:38:46 +00:00
feat(toggle): allow toggling global options. Fixes #534
This commit is contained in:
parent
770df9e5cf
commit
b50effc967
5 changed files with 30 additions and 23 deletions
|
@ -138,7 +138,7 @@ function Toggle:_wk(keys, mode)
|
|||
end
|
||||
|
||||
---@param option string
|
||||
---@param opts? snacks.toggle.Config | {on?: unknown, off?: unknown}
|
||||
---@param opts? snacks.toggle.Config | {on?: unknown, off?: unknown, global?: boolean}
|
||||
function M.option(option, opts)
|
||||
opts = opts or {}
|
||||
local on = opts.on == nil and true or opts.on
|
||||
|
@ -147,9 +147,16 @@ function M.option(option, opts)
|
|||
id = option,
|
||||
name = option,
|
||||
get = function()
|
||||
if opts.global then
|
||||
return vim.opt[option]:get() == on
|
||||
end
|
||||
return vim.opt_local[option]:get() == on
|
||||
end,
|
||||
set = function(state)
|
||||
if opts.global then
|
||||
vim.opt[option] = state and on or off
|
||||
return
|
||||
end
|
||||
vim.opt_local[option] = state and on or off
|
||||
end,
|
||||
}, opts)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue