Skip to content

Commit 8937783

Browse files
Fix: Switch Tabs During Comment Creation (#200)
Fix: Allow users to switch tabs while creating comments
1 parent 00e3e24 commit 8937783

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

lua/gitlab/reviewer/init.lua

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ local diffview_lib = require("diffview.lib")
99
local M = {
1010
bufnr = nil,
1111
tabnr = nil,
12+
stored_win = nil,
1213
}
1314

1415
-- Checks for legacy installations, only Diffview is supported.
@@ -199,7 +200,14 @@ M.is_current_sha = function()
199200
local view = diffview_lib.get_current_view()
200201
local layout = view.cur_layout
201202
local b_win = u.get_window_id_by_buffer_id(layout.b.file.bufnr)
203+
local a_win = u.get_window_id_by_buffer_id(layout.a.file.bufnr)
202204
local current_win = vim.fn.win_getid()
205+
206+
-- Handle cases where user navigates tabs in the middle of making a comment
207+
if a_win ~= current_win and b_win ~= current_win then
208+
current_win = M.stored_win
209+
M.stored_win = nil
210+
end
203211
return current_win == b_win
204212
end
205213

@@ -266,6 +274,7 @@ M.set_callback_for_file_changed = function(callback)
266274
pattern = { "DiffviewDiffBufWinEnter" },
267275
group = group,
268276
callback = function(...)
277+
M.stored_win = vim.api.nvim_get_current_win()
269278
if M.tabnr == vim.api.nvim_get_current_tabpage() then
270279
callback(...)
271280
end

0 commit comments

Comments
 (0)