Fix: Write to correct window if user changes during loading state (#167)

This MR fixes issue #165 where you could accidentally load the discussions tree into the wrong window if you switched while the content was still loading. This is a PATCH release.
This commit is contained in:
Harrison (Harry) Cramer
2024-01-20 23:35:56 -05:00
committed by GitHub
parent a01a3210c1
commit b623c06119

View File

@@ -105,6 +105,9 @@ M.toggle = function(callback)
return return
end end
local current_window = vim.api.nvim_get_current_win() -- Save user's current window in case they switched while content was loading
vim.api.nvim_set_current_win(M.split.winid)
M.rebuild_discussion_tree() M.rebuild_discussion_tree()
M.rebuild_unlinked_discussion_tree() M.rebuild_unlinked_discussion_tree()
M.add_empty_titles({ M.add_empty_titles({
@@ -118,6 +121,8 @@ M.toggle = function(callback)
M.switch_can_edit_bufs(false) M.switch_can_edit_bufs(false)
winbar.update_winbar(M.discussions, M.unlinked_discussions, default_discussions and "Discussions" or "Notes") winbar.update_winbar(M.discussions, M.unlinked_discussions, default_discussions and "Discussions" or "Notes")
vim.api.nvim_set_current_win(current_window)
if type(callback) == "function" then if type(callback) == "function" then
callback() callback()
end end