-
-
Notifications
You must be signed in to change notification settings - Fork 385
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
list: save and restore cursor positions #533
base: harpoon2
Are you sure you want to change the base?
Conversation
56f728d
to
3d45f6f
Compare
@ThePrimeagen could you please review this PR? It addresses a long-awaited fix. |
This seems like an improvement, but doesn't appear to work unless you first navigate to the file using harpoon. I have tested this with sync_on_ui_close both true and false. For example:
Adding this autocmd appears to fixe this issue with the default config. vim.api.nvim_create_autocmd({ "QuitPre" }, {
pattern = "*",
callback = function()
local bufnr = vim.api.nvim_get_current_buf()
local path = vim.api.nvim_buf_get_name(bufnr)
for _, it in ipairs(Harpoon:list().items) do
local value = it.value
if value == path then
Harpoon:list():append() -- now Harpoon:list():add()
break
end
end
end,
}) However, I still have an issue with the position not updating when switching between files (not using harpoon) and then navigating to the file using harpoon. Easy example of this is make a mark, move down, go to alternate file, go back using harpoon and you will be where the mark is and not where you last left off. I guess this is a different issue since it isn't while quitting, but it seems similar. |
I have done a lot of work on getting cursors to save constantly. The latest update does a distributed file style based on settings key, this allows saving upon every change I would first make sure the latest harpoon2 still has the issue you're looking for |
@ThePrimeagen I just checked with latest, harpoon2 does still have the issue. I was able to update the changes @davvid made to work with the latest harpoon2. Those changes along with the now much simpler autocmd seem to be working. vim.api.nvim_create_autocmd({ "QuitPre" }, {
pattern = "*",
callback = function()
-- Do this for all your lists
Harpoon:list():sync_cursor()
end,
}) I tried putting it in harpoon/init.lua and using _for_each_list, but it did not work. my updated branch https://github.com/maxrzaw/harpoon/tree/sync-cursor seems to be working. There might be some redundancies with the combination of the new changes to harpoon2 and the changes from this PR. |
797e89b
to
99f2dbe
Compare
99f2dbe
to
8ce76c3
Compare
Thanks for the heads-up @maxrzaw -- I've rebased this branch and updated to the latest harpoon2. The out-of-bounds cursor tests had to be updated with these changes, which I suspect is okay since the results are getting updated to match the file bounds. That's probably worth another look. @maxrzaw is the expectation that users will need to install the The behavior is better for more scenarios with these changes at least. w/out these changes the cursor position is lost even when switching between two harpooned files. For example, move around in one file, harpoon to a 2nd file, and then harpoon back and the cursor will be in a different position from whence we came. It's in the correct position when using this branch. Things Curious, which scenario does the autocmd handle? I don't see any change in behavior when using opts = {
settings = {
save_on_toggle = true,
sync_on_ui_close = true,
},
}, |
Harpoon was not remembering the cursor position after quitting nvim. Ensure that the cursor information is always saved and applied so that we get back to exactly where we last were in the harpooned file. Closes: ThePrimeagen#441
2125cf1
to
e639279
Compare
e639279
to
9eea06a
Compare
For me the position isn't being saved when I quit, regardless of whether I save the buffer or not. The only way I've found to make it work is by toggling the Harpoon list again (leader + h), selecting the same file from the list that's already open, and then quitting. Doing this saves the current position, allowing me to jump back to it when quitting Nvim and reopening the file via Harpoon. All other solutions don't work including AutoCmd suggested by @maxrzaw. |
Latest commit of which branch? I was using latest on harpoon2 with additional changes from this branch. https://github.com/maxrzaw/harpoon/tree/sync-cursor to be exact. |
These steps:
The key is that I open a harpooned file and move the cursor, but do nothing at all to interact with harpoon, then quit, this results in _for_each_list not working as expected. |
Let me double check everything, I think I know what happened. I should get some time this week to go over everything |
harpoon2
|
Harpoon was not remembering the cursor position after quitting nvim.
Ensure that the cursor information is always saved and applied so that
we get back to exactly where we last were in the harpooned file.
Closes: #441