From fabb652b8dceaea12a2879d93a9fe3a71c58ff46 Mon Sep 17 00:00:00 2001 From: Ade Attwood Date: Fri, 29 Jul 2022 21:02:40 +0100 Subject: [PATCH] fix: ensure results buffer cant go out of bounds --- lua/ivy/controller.lua | 9 +++++++++ lua/ivy/window.lua | 1 - 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lua/ivy/controller.lua b/lua/ivy/controller.lua index 28cf2fd..ff11426 100644 --- a/lua/ivy/controller.lua +++ b/lua/ivy/controller.lua @@ -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 diff --git a/lua/ivy/window.lua b/lua/ivy/window.lua index ee2f23d..addefc1 100644 --- a/lua/ivy/window.lua +++ b/lua/ivy/window.lua @@ -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