From c54176b5322a8ceac14a81902e7afb631f0dcfbe Mon Sep 17 00:00:00 2001 From: JoeDaBu Date: Tue, 17 Dec 2024 17:18:24 -0800 Subject: [PATCH] fixed a bug where changing to a new buffer enabled autotag --- lua/nvim-ts-autotag/config/plugin.lua | 13 ++++++------- lua/nvim-ts-autotag/internal.lua | 11 +++++++++-- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/lua/nvim-ts-autotag/config/plugin.lua b/lua/nvim-ts-autotag/config/plugin.lua index 72de152..92fdaba 100644 --- a/lua/nvim-ts-autotag/config/plugin.lua +++ b/lua/nvim-ts-autotag/config/plugin.lua @@ -172,13 +172,8 @@ end --- Do general plugin setup ---@param opts nvim-ts-autotag.PluginSetup? -function Setup.setup(config) - if config then - Setup.opts = config.opts - opts = Setup.opts - else - opts = {} - end +function Setup.setup(opts) + opts = opts or {} if Setup.did_setup() then return end @@ -243,4 +238,8 @@ function Setup.get_opts(filetype) return Setup.opts end + +function Setup.toggle() + Setup.get_opts().enable = not Setup.get_opts().enable +end return Setup diff --git a/lua/nvim-ts-autotag/internal.lua b/lua/nvim-ts-autotag/internal.lua index 291e39b..f737e39 100644 --- a/lua/nvim-ts-autotag/internal.lua +++ b/lua/nvim-ts-autotag/internal.lua @@ -470,6 +470,11 @@ M.attach = function(bufnr) if TagConfigs:get(vim.bo.filetype) ~= nil then setup_ts_tag() + -- this uses a new instance of opts from a new call to Setup + -- vim.notify('function#if#if Setup.opts.enable: ' .. vim.inspect(Setup.opts)) -- __AUTO_GENERATED_PRINT_VAR_END__ + if not Setup.get_opts().enable then + return + end local group = vim.api.nvim_create_augroup("nvim-ts-autotag-" .. bufnr, { clear = true }) if Setup.get_opts(vim.bo.filetype).enable_close then vim.keymap.set("i", ">", function() @@ -576,11 +581,13 @@ function M.buffers() end M.toggle = function() - Setup.opts.enable = not Setup.opts.enable - if Setup.opts.enable then + Setup.toggle() + if Setup.get_opts().enable then M.enable() + vim.notify('autotag toggled on') else M.disable() + vim.notify('autotag toggled off') end end