ThePrimeagen / harpoon

MIT License
6.87k stars 368 forks source link

"Add" does not sync list for relative navigation #552

Open nmiguel opened 6 months ago

nmiguel commented 6 months ago

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:

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,
}
ThePrimeagen commented 6 months ago

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?

nmiguel commented 6 months ago

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: image 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.

kimabrandt-flx commented 6 months ago

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.

nmiguel commented 6 months ago

@kimabrandt-flx this would definitely be a solution for the behaviour I'm looking for.

kimabrandt-flx commented 5 months ago

I've made an attempt at this, in #574.

nmiguel commented 5 months ago

I've made an attempt at this, in #574.

I've been using this and it's exactly what I needed. Thanks