From 74781e2d6dbb7264dc03c1f61fbdebeb76a10872 Mon Sep 17 00:00:00 2001 From: jaredgoldman Date: Wed, 10 Apr 2024 20:00:12 -0400 Subject: [PATCH] feat: toggle harpoon --- lua/config/harpoon.lua | 23 +++++++++-------------- lua/keymaps.lua | 2 +- requirements.md | 1 + 3 files changed, 11 insertions(+), 15 deletions(-) diff --git a/lua/config/harpoon.lua b/lua/config/harpoon.lua index e0bed28..2378a6d 100644 --- a/lua/config/harpoon.lua +++ b/lua/config/harpoon.lua @@ -20,14 +20,15 @@ local function toggle_telescope(harpoon_files) }) :find() end - -local function maybe_remove_add() - local bufnr = api.nvim_get_current_buf() - local mark = harpoon:mark(bufnr) - if mark then - harpoon:list():add() +local function toggle_mark() + local current_file = api.nvim_buf_get_name(0) -- Get the current buffer's file path + local item, index = harpoon:list():get_by_value(current_file) + if item then + harpoon:list():remove_at(index) + print("Removed from Harpoon: " .. current_file) else - harpoon:list():remove() + harpoon:list():add({ value = current_file }) + print("Added to Harpoon: " .. current_file) end end @@ -39,13 +40,7 @@ api.nvim_create_user_command("HarpoonAdd", function() harpoon:list():add() end, { bang = true }) api.nvim_create_user_command("HarpoonToggleFile", function() - maybe_remove_add() -end, { bang = true }) -api.nvim_create_user_command("HarpoonTogglePrev", function() - harpoon:list():prev() -end, { bang = true }) -api.nvim_create_user_command("HarpoonToggleNext", function() - harpoon:list():next() + toggle_mark() end, { bang = true }) api.nvim_create_user_command("HarpoonUI", function() toggle_telescope(harpoon:list()) diff --git a/lua/keymaps.lua b/lua/keymaps.lua index b566b3e..d4bce19 100644 --- a/lua/keymaps.lua +++ b/lua/keymaps.lua @@ -30,7 +30,7 @@ local mappings = { -- FTerm ["h"] = "FTermToggle", -- Harpoon - ["a"] = "HarpoonAdd", + ["a"] = "HarpoonToggleFile", [""] = "HarpoonUI", ["c"] = "HarpoonClear", -- Formating diff --git a/requirements.md b/requirements.md index 18b1be5..25f08d2 100644 --- a/requirements.md +++ b/requirements.md @@ -12,4 +12,5 @@ - lua vim linting x - dashboard x - suppress vim global warnings x +- harpoon toggle file - debugger