Skip to content

Commit

Permalink
fixed a bug where changing to a new buffer enabled autotag
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeDaBu committed Dec 18, 2024
1 parent 36dbb20 commit c54176b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
13 changes: 6 additions & 7 deletions lua/nvim-ts-autotag/config/plugin.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
11 changes: 9 additions & 2 deletions lua/nvim-ts-autotag/internal.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit c54176b

Please sign in to comment.