From a38ae2fa75ad027f8c3b043efdbcde61de55da37 Mon Sep 17 00:00:00 2001 From: Tomas Slusny Date: Fri, 24 May 2024 16:00:11 +0200 Subject: [PATCH] fix: check if buffer is in chat window to validate chat being visible (#330) * fix: check if buffer is in chat window to validate chat being visible This prevents someone replacing buffer in copilot chat window with other buffer and chat not being able to recover * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- lua/CopilotChat/chat.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lua/CopilotChat/chat.lua b/lua/CopilotChat/chat.lua index 7a9d44f3..4f7c22a3 100644 --- a/lua/CopilotChat/chat.lua +++ b/lua/CopilotChat/chat.lua @@ -61,7 +61,9 @@ local Chat = class(function(self, mark_ns, help, on_buf_create) end, Overlay) function Chat:visible() - return self.winnr and vim.api.nvim_win_is_valid(self.winnr) + return self.winnr + and vim.api.nvim_win_is_valid(self.winnr) + and vim.api.nvim_win_get_buf(self.winnr) == self.bufnr end function Chat:active()