From eab6c9c032af8a967379aad41d0c31f47d7e56d7 Mon Sep 17 00:00:00 2001 From: Mivort Date: Wed, 17 Jan 2024 20:46:33 +0000 Subject: [PATCH] fix: avoid exception when calling :Reject on last element This commit adds array length check gate before setting the cursor position on list entry removal with `:Reject` command. It allows to avoid the following exception which gets produced otherwise: ``` E5108: Error executing lua .../qf_helper.nvim/lua/qf_helper.lua:180: Cursor position outside buffer ``` --- lua/qf_helper.lua | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lua/qf_helper.lua b/lua/qf_helper.lua index b054c4a..3349fca 100644 --- a/lua/qf_helper.lua +++ b/lua/qf_helper.lua @@ -173,6 +173,9 @@ M.cmd_filter = function(keep, range_start, range_end) end end util.set_list(qftype, newlist) + if #newlist == 0 then + return + end lnum = math.min(math.max(1, lnum), #newlist) vim.api.nvim_win_set_cursor(0, { lnum, cursor[2] }) end