fix: ensure results buffer cant go out of bounds

This commit is contained in:
Ade Attwood 2022-07-29 21:02:40 +01:00
parent c9ce8ac4d1
commit fabb652b8d
2 changed files with 9 additions and 1 deletions

View file

@ -47,11 +47,20 @@ controller.checkpoint = function()
end
controller.next = function()
local max = vim.api.nvim_buf_line_count(window.buffer) - 1
if window.index == max then
return
end
window.index = window.index + 1
window.update()
end
controller.previous = function()
if window.index == 0 then
return
end
window.index = window.index - 1
window.update()
end

View file

@ -108,7 +108,6 @@ window.get_buffer = function()
end
window.update = function()
-- TODO(ade): Add a guard in so we can not go out of range on the results buffer
vim.api.nvim_win_set_cursor(window.window, { window.index + 1, 0 })
end