From 7ae136d07ed15ef227cdd1529d85109a905aca35 Mon Sep 17 00:00:00 2001 From: Aron Griffis Date: Thu, 20 Jul 2023 14:36:21 -0400 Subject: [PATCH] fix(util): attempt to concatenate a boolean If you passed a table of values { false, true } for example, then the code would attempt to concatenate the raw boolean in Util.info() Additionally, honor the silent option when explicit values are passed, and allow passing a single value and don't do anything if already set. --- lua/lazyvim/util/init.lua | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/lua/lazyvim/util/init.lua b/lua/lazyvim/util/init.lua index 10c82c13..4f91f34e 100644 --- a/lua/lazyvim/util/init.lua +++ b/lua/lazyvim/util/init.lua @@ -166,22 +166,28 @@ function M.float_term(cmd, opts) end ---@param silent boolean? ----@param values? {[1]:any, [2]:any} +---@param values? {[1]:any, [2]?:any} function M.toggle(option, silent, values) if values then if vim.opt_local[option]:get() == values[1] then + if values[2] == values[1] or values[2] == nil then + return -- Nothing to do + end vim.opt_local[option] = values[2] else vim.opt_local[option] = values[1] end - return Util.info("Set " .. option .. " to " .. vim.opt_local[option]:get(), { title = "Option" }) - end - vim.opt_local[option] = not vim.opt_local[option]:get() - if not silent then - if vim.opt_local[option]:get() then - Util.info("Enabled " .. option, { title = "Option" }) - else - Util.warn("Disabled " .. option, { title = "Option" }) + if not silent then + Util.info("Set " .. option .. " to " .. tostring(vim.opt_local[option]:get()), { title = "Option" }) + end + else + vim.opt_local[option] = not vim.opt_local[option]:get() + if not silent then + if vim.opt_local[option]:get() then + Util.info("Enabled " .. option, { title = "Option" }) + else + Util.warn("Disabled " .. option, { title = "Option" }) + end end end end