From 0280f8be12113d5c41ac31f17a585b04129418fa Mon Sep 17 00:00:00 2001 From: Bhanuka Date: Sun, 21 Mar 2021 13:53:16 +0530 Subject: [PATCH] Added nav_next and nav_prev functions This allows to cycle through the harpoon marks list --- lua/harpoon/mark.lua | 4 ++++ lua/harpoon/ui.lua | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/lua/harpoon/mark.lua b/lua/harpoon/mark.lua index 8e6ecef..a1accbd 100644 --- a/lua/harpoon/mark.lua +++ b/lua/harpoon/mark.lua @@ -203,5 +203,9 @@ end M.to_quickfix_list() +M.get_current_index = function() + return M.get_index_of(vim.fn.bufname(vim.fn.bufnr())) +end + return M diff --git a/lua/harpoon/ui.lua b/lua/harpoon/ui.lua index de3de3c..1f78c69 100644 --- a/lua/harpoon/ui.lua +++ b/lua/harpoon/ui.lua @@ -134,5 +134,38 @@ function M.close_notification(bufnr) vim.api.nvim_buf_delete(bufnr) end +M.nav_next = function() + local current_index = Marked.get_current_index() + local number_of_items = Marked.get_length() + + if current_index == nil then + current_index = 1 + else + current_index = current_index + 1 + end + + if (current_index > number_of_items) then + current_index = 1 + end + M.nav_file(current_index) +end + +M.nav_prev = function() + local current_index = Marked.get_current_index() + local number_of_items = Marked.get_length() + + if current_index == nil then + current_index = number_of_items + else + current_index = current_index - 1 + end + + if (current_index < 1) then + current_index = number_of_items + end + + M.nav_file(current_index) +end + return M