fix: Ensure autocmds IDs are removed when deleted

This commit is contained in:
hedy
2023-11-18 13:16:42 +08:00
parent 5726e23853
commit 62183f9d51

View File

@@ -79,6 +79,7 @@ local function __refresh()
if M.state.code_win ~= curwin then if M.state.code_win ~= curwin then
if M.state.autocmds[M.state.code_win] then if M.state.autocmds[M.state.code_win] then
vim.api.nvim_del_autocmd(M.state.autocmds[M.state.code_win]) vim.api.nvim_del_autocmd(M.state.autocmds[M.state.code_win])
M.state.autocmds[M.state.code_win] = nil
end end
end end
M.state.code_win = curwin M.state.code_win = curwin
@@ -87,6 +88,7 @@ local function __refresh()
if cfg.o.outline_items.highlight_hovered_item or cfg.o.symbol_folding.auto_unfold_hover then if cfg.o.outline_items.highlight_hovered_item or cfg.o.symbol_folding.auto_unfold_hover then
if M.state.autocmds[curwin] then if M.state.autocmds[curwin] then
vim.api.nvim_del_autocmd(M.state.autocmds[curwin]) vim.api.nvim_del_autocmd(M.state.autocmds[curwin])
M.state.autocmds[curwin] = nil
end end
if utils.str_or_nonempty_table(cfg.o.outline_items.auto_update_events.follow) then if utils.str_or_nonempty_table(cfg.o.outline_items.auto_update_events.follow) then
M.state.autocmds[curwin] = M.state.autocmds[curwin] =
@@ -436,6 +438,7 @@ local function handler(response, opts)
if cfg.o.outline_items.highlight_hovered_item or cfg.o.symbol_folding.auto_unfold_hover then if cfg.o.outline_items.highlight_hovered_item or cfg.o.symbol_folding.auto_unfold_hover then
if M.state.autocmds[M.state.code_win] then if M.state.autocmds[M.state.code_win] then
vim.api.nvim_del_autocmd(M.state.autocmds[M.state.code_win]) vim.api.nvim_del_autocmd(M.state.autocmds[M.state.code_win])
M.state.autocmds[M.state.code_win] = nil
end end
if utils.str_or_nonempty_table(cfg.o.outline_items.auto_update_events.follow) then if utils.str_or_nonempty_table(cfg.o.outline_items.auto_update_events.follow) then
M.state.autocmds[M.state.code_win] = M.state.autocmds[M.state.code_win] =