snacks.nvim icon indicating copy to clipboard operation
snacks.nvim copied to clipboard

bug(explorer): Selected files do not get opened in the last active buffer

Open nickjj opened this issue 9 months ago • 17 comments

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:

  1. Open nvim . in a directory (the dot is important)
  2. Open Snacks explorer
  3. Open a file
  4. Split the file with :vs and put your cursor in the right buffer
  5. Select another file in Snacks explorer either by pressing enter or double clicking with the mouse
  6. 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:

  1. Open nvim in a directory (no dot is important)
  2. Open a file
  3. :vs
  4. Click into the right buffer
  5. <leader>e to open the explorer
  6. Select the file with a double click
  7. It correctly loads in the right buffer
    • This is the same workflow as scenario one except how Neovim was launched
  8. Click into the left buffer
  9. Select any file in the explorer with a double click
  10. 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.

nickjj avatar Mar 16 '25 23:03 nickjj

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

dpetka2001 avatar Mar 17 '25 09:03 dpetka2001

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.

nickjj avatar Mar 17 '25 09:03 nickjj

I get the same behavior with bufferline.nvim disabled.

https://github.com/user-attachments/assets/f9d72a57-56c8-4b6f-b013-e7b76e201e00

dpetka2001 avatar Mar 17 '25 10:03 dpetka2001

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

dpetka2001 avatar Mar 17 '25 10:03 dpetka2001

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.

nickjj avatar Mar 17 '25 10:03 nickjj

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

nickjj avatar Mar 17 '25 10:03 nickjj

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

dpetka2001 avatar Mar 17 '25 10:03 dpetka2001

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 .?

dpetka2001 avatar Mar 17 '25 11:03 dpetka2001

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>e to 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

nickjj avatar Mar 17 '25 11:03 nickjj

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.

dpetka2001 avatar Mar 17 '25 11:03 dpetka2001

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?

nickjj avatar Mar 17 '25 11:03 nickjj

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.

dpetka2001 avatar Mar 17 '25 11:03 dpetka2001

Done, thanks again! It will be interesting to see the root cause of this one.

nickjj avatar Mar 17 '25 11:03 nickjj

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.

github-actions[bot] avatar Apr 17 '25 02:04 github-actions[bot]

Posting here since it's stale.

nickjj avatar Apr 17 '25 10:04 nickjj

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.

github-actions[bot] avatar May 18 '25 02:05 github-actions[bot]

Posting here since it's stale.

nickjj avatar May 18 '25 10:05 nickjj

+1

bertverbessem avatar Jun 02 '25 08:06 bertverbessem

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.

github-actions[bot] avatar Jul 03 '25 02:07 github-actions[bot]

No

dpetka2001 avatar Jul 03 '25 03:07 dpetka2001

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.

github-actions[bot] avatar Aug 03 '25 02:08 github-actions[bot]

shh

dpetka2001 avatar Aug 03 '25 10:08 dpetka2001

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

orestis avatar Sep 02 '25 07:09 orestis

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.

nickjj avatar Sep 02 '25 10:09 nickjj

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.

github-actions[bot] avatar Oct 03 '25 02:10 github-actions[bot]

Replying for staleness.

nickjj avatar Oct 03 '25 12:10 nickjj