Skip to content

Commit

Permalink
fix: Improve boundary checks around last position in buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
Tomas Slusny authored and deathbeam committed Mar 12, 2024
1 parent c5b0f79 commit 4b562ce
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lua/CopilotChat/chat.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 4b562ce

Please sign in to comment.