harpoon
harpoon copied to clipboard
"Add" does not sync list for relative navigation
When adding a new file, relative navigation does not work as expected the first time it is used, navigating as if the file was not just added. Here are a couple of examples:
-
Have 2 marks, be on the file with the second mark
-
Telescope to a third file
-
Add it to harpoon
-
Navigate to next mark
-
Expected: should go to file with mark 1. Observed: Nothing happens (I believe it goes from mark 2 to 3, navigating me to the same file).
-
Same scenario, but start from file with mark 1 before telescoping to the third file.
-
Add a mark and navigate to next
-
Expected to go to the file with mark 1. Observed: Goes to file with mark 2 (again, I believe it uses a previous state)
Here is my config:
return {
"ThePrimeagen/harpoon",
branch = "harpoon2",
lazy = false,
dependencies = {
"nvim-lua/plenary.nvim",
"nvim-telescope/telescope.nvim",
},
config = function()
local harpoon = require("harpoon")
-- REQUIRED
harpoon:setup()
-- REQUIRED
vim.keymap.set("n", "<leader>h", function()
harpoon.ui:toggle_quick_menu(harpoon:list())
end)
vim.keymap.set("n", "<leader>a", function()
harpoon:list():add()
end)
-- Toggle previous & next buffers stored within Harpoon list
vim.keymap.set("n", "<leader>f", function()
harpoon:list():prev({
ui_nav_wrap = true
})
end)
vim.keymap.set("n", "<leader>j", function()
harpoon:list():next({
ui_nav_wrap = true
})
end)
end,
}
ok...
this is a reason why i have always hated the prev
and next
stuff. I keep a pointer internally to what file you have selected and increment / decrement it depending on whether you next or prev.
the hard part is once i get clever this could become very confusing for people. What behavior would you like to see?
I agree that this could become very complicated very quickly. In my mind, the next
and prev
should not work based on the last navigation through harpoon, but rather through any navigation at all. In other words, if I have files foo
and bar
in my harpoon list, if I'm on foo
, the next
should be bar
, always, and regardless of the last harpoon navigation done. This way of looking at things would also fix my particular issue of when a file is added the internal pointer not being updated.
If it helps with visualizing my issue, I use the harpoon extension for lualine, which looks like this:
In it, you can see that I'm currently on file 2 of my harpoon list. Looking at it you would expect my
next
to go to file 3, and prev
to file 1, which may not be the result if I got to file 2 through Telescope or going to definition.
I'm not sure what would be the best way to approach this. I think my way of looking at this sort of navigation makes sense, but hearing your explanation of what is happening under the hood it also makes sense and makes me question if someone else is relying on this behaviour, in which case supporting my request would imply adding another config option.
Either way, thanks for the explanation and the great plugin.
Maybe - in the spirit of a harpoon - opening/selecting a buffer could update the internal pointer to the current item in the list, if there is a match!? When adding the current buffer, it would select the added item as the current one.
@kimabrandt-flx this would definitely be a solution for the behaviour I'm looking for.
I've made an attempt at this, in #574.
I've made an attempt at this, in #574.
I've been using this and it's exactly what I needed. Thanks