From 9478a8611b46399f9d2925c86ef5517650691feb Mon Sep 17 00:00:00 2001 From: Aotrix Date: Mon, 3 Mar 2025 19:34:20 +0100 Subject: added quickfix loop --- lua/aotrix/quickfix.lua | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) (limited to 'lua/aotrix') diff --git a/lua/aotrix/quickfix.lua b/lua/aotrix/quickfix.lua index f1f1008..71a8677 100644 --- a/lua/aotrix/quickfix.lua +++ b/lua/aotrix/quickfix.lua @@ -21,7 +21,9 @@ vim.api.nvim_create_autocmd('DiagnosticChanged', { end end }) -local current_quickfix_line = 1 +local get_current_quickfix_index = function() + return tonumber(vim.fn.getqflist({idx = 0})['idx']) +end vim.keymap.set("n", "q", function() if #vim.diagnostic.get() > 0 then if quickfix_is_open then @@ -30,29 +32,24 @@ vim.keymap.set("n", "q", function() else vim.diagnostic.setqflist() vim.cmd.cfirst() - current_quickfix_line = 1 end end end) vim.keymap.set("n", "", function() if #vim.diagnostic.get() > 0 and quickfix_is_open then - if current_quickfix_line < nb_elements_quickfix then + if get_current_quickfix_index() < nb_elements_quickfix then vim.cmd.cnext() - current_quickfix_line = current_quickfix_line + 1 else vim.cmd.cfirst() - current_quickfix_line = 1 end end end) vim.keymap.set("n", "", function() if #vim.diagnostic.get() > 0 and quickfix_is_open then - if current_quickfix_line > 1 then + if get_current_quickfix_index() > 1 then vim.cmd.cprev() - current_quickfix_line = current_quickfix_line - 1 else vim.cmd.clast() - current_quickfix_line = nb_elements_quickfix end end end) -- cgit v1.2.3