SmiteshP / nvim-navbuddy

A simple popup display that provides breadcrumbs feature using LSP server
Apache License 2.0
770 stars 30 forks source link

Push old cursor position to jumplist on select #12

Closed aaronkollasch closed 1 year ago

aaronkollasch commented 1 year ago

After selecting a node, I expect to be able to navigate back to my original position using <C-o> to move backwards in the jump list. However, nvim_win_set_cursor() does not add to the jumplist.

Instead, I set cursor to the start position, then navigate to the new position using a G command, which does add to the jumplist. Because the second action happens immediately, I don't see a visual artifact from jumping to the old position.

Now <C-o> and <C-i> work as expected.

Relevant stackoverflow: https://stackoverflow.com/questions/19195160/push-a-location-to-the-jumplist I experimented with setting a mark with normal! m`, but it didn't seem to work.

SmiteshP commented 1 year ago

Rather than using "%dG%d|" to move cursor around I would prefer lua api's function itself. Just so that its readable. And experimenting with normal! m' seems to be working fine.

aaronkollasch commented 1 year ago

Sounds good. Actually, when experimenting with setting the mark, I hadn't moved to the start cursor first. So, this code works instead:

vim.api.nvim_win_set_cursor(display.for_win, display.start_cursor)
vim.api.nvim_command("normal! m'")
vim.api.nvim_win_set_cursor(display.for_win, {display.focus_node.name_range["start"].line,
                                              display.focus_node.name_range["start"].character})
aaronkollasch commented 1 year ago

I've now updated the PR with your suggestions.

aaronkollasch commented 1 year ago

Thanks!