Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Navigation Behavior of Next/Previous in Harpoon #632

Open
ahmedreda1009 opened this issue Sep 29, 2024 · 2 comments
Open

Navigation Behavior of Next/Previous in Harpoon #632

ahmedreda1009 opened this issue Sep 29, 2024 · 2 comments

Comments

@ahmedreda1009
Copy link

ahmedreda1009 commented Sep 29, 2024

What issue are you having that you need Harpoon to solve?

I am experiencing an unexpected navigation behavior when using the next and previous commands in Harpoon. When I navigate to a specific harpooned file directly from the Harpoon list, subsequent calls to next or previous do not reference the newly selected file, but rather continue from the last navigation point. This behavior can be confusing and disrupts the flow of working with multiple files.

Why doesn’t the current config help?

The current configuration of Harpoon maintains a navigation history that does not reset when a file is selected directly from the Harpoon UI. As a result, the next and previous commands continue to operate based on the last accessed file, rather than the currently displayed file. This inconsistency makes it challenging to navigate efficiently between files, especially when the user switches contexts frequently.

What proposed API changes are you suggesting?

I suggest implementing a mechanism to reset or update the navigation history whenever a file is directly selected from the Harpoon list. This could involve:

  • Modifying the harpoon:list():go_to(index) method to update the current navigation context after selecting a file.
  • Ensuring that the next and previous commands reference the new current file for navigation, rather than relying on the previous state.

By making these changes, the plugin would provide a more intuitive and cohesive navigation experience, allowing users to easily move between files in a way that reflects their current context.

@PedroBinotto
Copy link

can you please share a snippet from your config where you call the aforementioned operations?

@eoBattisti
Copy link

If the problem is related to Harpoon 2, the problem is that when you select an item from HarpoonList through the <CR> keybind while in the Harpoon toggle ui, it only will select the desired item but will not update the the value of HarpoonList._index as done by the HarpoonList:next() and also HarpoonList:prev() see the source code below:

function HarpoonList:select(index, options)
    local item = self.items[index]
    if item or self.config.select_with_nil then
        Extensions.extensions:emit(
            Extensions.event_names.SELECT,
            { list = self, item = item, idx = index }
        )
        self.config.select(item, self, options)
    end
end

---
--- @param opts? HarpoonNavOptions
function HarpoonList:next(opts)
    opts = opts or {}

    self._index = self._index + 1
    if self._index > self._length then
        if opts.ui_nav_wrap then
            self._index = 1
        else
            self._index = self._length
        end
    end

    self:select(self._index)
end

---
--- @param opts? HarpoonNavOptions
function HarpoonList:prev(opts)
    opts = opts or {}

    self._index = self._index - 1
    if self._index < 1 then
        if opts.ui_nav_wrap then
            self._index = #self.items
        else
            self._index = 1
        end
    end

    self:select(self._index)
end

So imho the behaviour of HarpoonList:select() should also update the index, so the it does not break the navigation flow and also make it consistent between all 3 methods.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants