fix: Do not create error when generating annotation on empty file

This commit is contained in:
danymat
2022-01-25 14:27:53 +01:00
parent 015076cdde
commit 4c6b4e6d5e
2 changed files with 9 additions and 2 deletions

View File

@@ -124,7 +124,14 @@ neogen.generate = function(opts)
-- Create extmark to jump back to current location
local pos = vim.api.nvim_win_get_cursor(0)
neogen.utilities.cursor.create(pos[1], pos[2] + 1)
local col = pos[2] + 2
-- If the line we are in is empty, it will throw an error out of bounds.
if vim.api.nvim_get_current_line() == "" then
col = pos[2] + 1
end
neogen.utilities.cursor.create(pos[1], col)
-- Creates extmark for the end of the content
neogen.utilities.cursor.create(to_place + #content + 1, 0)