From b6f023373a9d4fbf8b68779e11c6ec6ec53125e5 Mon Sep 17 00:00:00 2001 From: "Harrison (Harry) Cramer" <32515581+harrisoncramer@users.noreply.github.com> Date: Mon, 22 Jan 2024 07:30:08 -0500 Subject: [PATCH] Fix: De-Register Tabpage on Correct Close Event (#168) This fixes a bug where the reviewer tab would be erroneously marked as closed. This is a PATCH release. --- lua/gitlab/reviewer/diffview.lua | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/lua/gitlab/reviewer/diffview.lua b/lua/gitlab/reviewer/diffview.lua index 79919b5..3aba9f6 100644 --- a/lua/gitlab/reviewer/diffview.lua +++ b/lua/gitlab/reviewer/diffview.lua @@ -50,17 +50,15 @@ M.open = function() u.notify("This merge request has conflicts!", vim.log.levels.WARN) end - local group = vim.api.nvim_create_augroup("gitlab.diffview.autocommand.close", {}) - vim.api.nvim_create_autocmd("User", { - pattern = { "DiffviewViewClosed" }, - group = group, - callback = function() - --Check if our diffview tab was closed - if vim.api.nvim_tabpage_is_valid(M.tabnr) then - M.tabnr = nil - end - end, - }) + -- Register Diffview hook for close event to set tab page # to nil + local on_diffview_closed = function(view) + if view.tabpage == M.tabnr then + M.tabnr = nil + end + end + require("diffview.config").user_emitter:on("view_closed", function(_, ...) + on_diffview_closed(...) + end) if state.settings.discussion_tree.auto_open then local discussions = require("gitlab.actions.discussions")