Skip to content

Commit d4d63a2

Browse files
authored
fix(ui): prevent errors when restoring invalid window (#1539)
- Add a check in Overlay:restore to ensure the window is valid before attempting to set the buffer, preventing errors if the window was closed. - Scope the close keymap in chat buffer to the buffer only, avoiding global keymap pollution. Closes #1535
1 parent 9fec6c3 commit d4d63a2

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

lua/CopilotChat/ui/chat.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ local Chat = class(function(self, config, on_buf_create)
161161
function(bufnr)
162162
vim.keymap.set('n', config.mappings.close.normal, function()
163163
self.chat_overlay:restore(self.winnr, self.bufnr)
164-
end)
164+
end, { buffer = bufnr })
165165

166166
vim.api.nvim_create_autocmd({ 'BufHidden', 'BufDelete' }, {
167167
buffer = bufnr,

lua/CopilotChat/ui/overlay.lua

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,10 @@ function Overlay:restore(winnr, bufnr)
116116
self.on_hide(self.bufnr)
117117
end
118118

119+
if not vim.api.nvim_win_is_valid(winnr) then
120+
return
121+
end
122+
119123
vim.api.nvim_win_set_buf(winnr, bufnr)
120124

121125
if self.cursor then

0 commit comments

Comments
 (0)