From 4b562ce7316291f728465bc26a72d8f6c230d0a4 Mon Sep 17 00:00:00 2001 From: Tomas Slusny Date: Tue, 12 Mar 2024 13:47:17 +0100 Subject: [PATCH] fix: Improve boundary checks around last position in buffer --- lua/CopilotChat/chat.lua | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lua/CopilotChat/chat.lua b/lua/CopilotChat/chat.lua index ae82659c..8e5ee41a 100644 --- a/lua/CopilotChat/chat.lua +++ b/lua/CopilotChat/chat.lua @@ -71,7 +71,13 @@ end function Chat:last() self:validate() local last_line = vim.api.nvim_buf_line_count(self.bufnr) - 1 + if last_line < 0 then + return 0, 0 + end local last_line_content = vim.api.nvim_buf_get_lines(self.bufnr, -2, -1, false) + if not last_line_content or #last_line_content == 0 then + return last_line, 0 + end local last_column = #last_line_content[1] return last_line, last_column end