bug(explorer): Selected files do not get opened in the last active buffer
Did you check docs and existing issues?
- [x] I have read all the snacks.nvim docs
- [x] I have updated the plugin to the latest version before submitting this issue
- [x] I have searched the existing issues of snacks.nvim
- [x] I have searched the existing issues of plugins related to this issue
Neovim version (nvim -v)
v0.10.4
Operating system/version
Ubuntu 22.04 LTS (WSL 2)
Describe the bug
When opening files with enter or double clicking with the mouse, the file always gets opened in the left most buffer.
Steps To Reproduce
Scenario 1:
- Open
nvim .in a directory (the dot is important) - Open Snacks explorer
- Open a file
- Split the file with
:vsand put your cursor in the right buffer - Select another file in Snacks explorer either by pressing enter or double clicking with the mouse
- The selected file will open in the left buffer instead of the right
If you split the files top / bottom instead of left / right, it chooses the top buffer instead of the bottom too.
Scenario 2:
- Open
nvimin a directory (no dot is important) - Open a file
:vs- Click into the right buffer
<leader>eto open the explorer- Select the file with a double click
- It correctly loads in the right buffer
- This is the same workflow as scenario one except how Neovim was launched
- Click into the left buffer
- Select any file in the explorer with a double click
- It incorrectly loads in the right buffer
- For this last one, the expectation would be the left buffer since it was the last active buffer
There is further discussion and videos posted in the comments. Thank you @dpetka2001 for helping uncover more precise testing instructions.
Expected Behavior
In both scenarios, the file gets opened in the last active buffer. If multiple tabs are open, it would be the last active buffer in whatever tab you have focused.
Most of the time I am using the picker to pick a file and the picker behaves with the expected behavior.
Can't repro with fresh LazyVim installation which I assume you also use based on your activity on LazyVim repo. Screencast following
https://github.com/user-attachments/assets/baa66e96-98b9-48c6-9b13-132f4c54a04a
Thanks, yep I am using LazyVim.
One difference I see is you have bufferline active because the explorer file was opened in a new "buffer tab".
I have that plugin disabled with:
return {
{ "akinsho/bufferline.nvim", enabled = false },
}
Can you try with that? If you can repeat it, I will edit my issue to include this detail.
I get the same behavior with bufferline.nvim disabled.
https://github.com/user-attachments/assets/f9d72a57-56c8-4b6f-b013-e7b76e201e00
Try with a fresh LazyVim installation and see if you can repro.
1. mkdir ~/.config/lazytest
2. git clone https://github.com/LazyVim/starter ~/.config/lazytest
3. NVIM_APPNAME=lazytest nvim and wait for the installation to complete
4. While Lazy UI is still open press `C` to check and `U` to make sure everything is updated
5. Restart Neovim with command from step 3. Add a plugin spec that disables `bufferline.nvim` and restart Neovim again with command from step 3
6. Open a buffer, do `:vsplit` and then press `<leader>e` to open `snacks.explorer` and choose a file to open
For me with the above steps the file from Snacks.explorer still opens in the right vertical split window as also shown in the video.
For cleanup
rm -rf ~/.config/lazytest
rm -rf ~/.local/share/lazytest
rm -rf ~/.local/state/lazytest
rm -rf ~/.cache/lazytest
I found the discrepency in our testing instructions.
In my original steps I put this as step 3 "Split the file with :vs and put your cursor in the right buffer".
I clicked into the right buffer before moving onto step 4. If you don't do this step then I get the same results as your video.
Can you try with the above and see if you can reproduce? Happy to record a video showing both testing instructions and how they produce different results if requested.
I've went ahead and recorded a video anyways since it will be helpful to document:
https://github.com/user-attachments/assets/3d80df66-da61-4aae-b918-738f8cf351a7
Still not able to repro even with clicking with the mouse on the right window
https://github.com/user-attachments/assets/8c590aab-952d-4a7a-8e36-9ad8ef153868
Ok, I think I found the discrepancy. It's the difference how you invoke Neovim. When you do nvim and then just restore a session or search for a file and open it in a buffer, I can't repro. But when you do nvim . to open Neovim with a directory argument, then I can repro.
Really weird behavior. No idea why this happens.
PS: Could you confirm the behavior when you just do nvim and then do nvim .?
If I launch with nvim instead of nvim . I get the expected behavior but not all the time.
Here's another workflow to produce even more weird behavior.
It only works the first time you click into the right buffer.
Try this with nvim:
- Open a file
:vs- Click into the right buffer
<leader>eto open the explorer- Select the file with a double click
- It correctly loads in the right buffer
- Click into the left buffer
- Select any file in the explorer with a double click
- It incorrectly loads in the right buffer
- For this last one, the expectation would be the left buffer since it was the last active buffer
Yes, I can confirm this happens. It seems that the Explorer picker always keeps track of the last active window and always opens a file in that window. You would have to close the Explorer, move your cursor to another window to make it active and then open the Explorer again and choose another file to open in that window.
No idea why this happens.
Thank you for the confirmation and uncovering more precise steps to repeat it. To keep things easier to read, would you like me to edit the original issue with these details?
Yes, I believe it would be helpful for the maintainer to read everything that transpires in your original post instead of having to go through all our comments to get a grasp of what's happening.
Hopefully, he will have a better idea of why this happens.
Done, thanks again! It will be interesting to see the root cause of this one.
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 7 days.
Posting here since it's stale.
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 7 days.
Posting here since it's stale.
+1
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 7 days.
No
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 7 days.
shh
I'm also having a hard time with this - the behaviour is seemingly random, ideally what I'd want is always use the current active window. If I want a different window I can do a <shift-CR> to pick it explicitly...
Yep, the same thing happens to me. I haven't figured out exactly what's happening but it's still an issue with the latest release of this tool, LazyVim and Neovim.
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 7 days.
Replying for staleness.