diff --git a/lua/gitlab/reviewer/init.lua b/lua/gitlab/reviewer/init.lua index 3c184908..a04727fb 100644 --- a/lua/gitlab/reviewer/init.lua +++ b/lua/gitlab/reviewer/init.lua @@ -9,6 +9,7 @@ local diffview_lib = require("diffview.lib") local M = { bufnr = nil, tabnr = nil, + stored_win = nil, } -- Checks for legacy installations, only Diffview is supported. @@ -199,7 +200,14 @@ M.is_current_sha = function() local view = diffview_lib.get_current_view() local layout = view.cur_layout local b_win = u.get_window_id_by_buffer_id(layout.b.file.bufnr) + local a_win = u.get_window_id_by_buffer_id(layout.a.file.bufnr) local current_win = vim.fn.win_getid() + + -- Handle cases where user navigates tabs in the middle of making a comment + if a_win ~= current_win and b_win ~= current_win then + current_win = M.stored_win + M.stored_win = nil + end return current_win == b_win end @@ -266,6 +274,7 @@ M.set_callback_for_file_changed = function(callback) pattern = { "DiffviewDiffBufWinEnter" }, group = group, callback = function(...) + M.stored_win = vim.api.nvim_get_current_win() if M.tabnr == vim.api.nvim_get_current_tabpage() then callback(...) end