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

bug(terminal): Focus Shift to Incorrect Split After Toggling Terminal

Open samuelborn opened this issue 1 year ago • 2 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)

0.10.3

Operating system/version

Fedora Linux

Describe the bug

If I have multiple vsplits open and toggle the terminal on and then off, always the left most window is selected afterwards. It should however jump back to the previously open one.

Steps To Reproduce

  1. nvim -u repro.lua
  2. Open split <C-w>v
  3. Jump to right window <C-w>l
  4. Open terminal :lua Snacks.terminal()
  5. Close terminal :lua Snacks.terminal()
  6. Cursor now again in left window

Expected Behavior

After close the cursor goes to the position it was before opening the terminal, notably also the same window.

Repro

vim.env.LAZY_STDPATH = ".repro"
load(vim.fn.system("curl -s https://raw.githubusercontent.com/folke/lazy.nvim/main/bootstrap.lua"))()

require("lazy.minit").repro({
  spec = {
    { "folke/snacks.nvim", opts = {} },
  },
})

samuelborn avatar Feb 06 '25 09:02 samuelborn

I'm seeing when I have a terminal in a split and then open any picker from the terminal window, closing the picker always selects the non-terminal split.

liamhennebury avatar Feb 15 '25 12:02 liamhennebury

super annoying issue, happens to me multiple times a day every day. would be great to see this fixed

iniw avatar Feb 18 '25 13:02 iniw

@folke any chance you could take a look at this? I tried fixing it myself yesterday but it seemed non-trivial since terminals are just reusing the win infrastructure

iniw avatar Feb 19 '25 09:02 iniw

@folke I still see the issue here's a video of it. You can see when I'm in the terminal window and launch the picker I always end up in the other split.

https://github.com/user-attachments/assets/33d3c570-f7d9-4c2a-82f7-750a37de8d6b

liamhennebury avatar Feb 19 '25 23:02 liamhennebury

@liamhennebury i was able to reproduce your problem. You may want to open another issue though, as this seems unrelated. On the latest version the problem i initially described is fixed.

samuelborn avatar Feb 20 '25 09:02 samuelborn

That other problem with picker as well. Just update

folke avatar Feb 20 '25 09:02 folke

Yep, you are right. I thought i updated it, because the other issue was gone.

But you are right. Everything works as expected now. Thank you! ❤

samuelborn avatar Feb 20 '25 10:02 samuelborn

@folke There's seems to a difference in behaviour between close vs cancel. cancel works as expected (goes to last window) but close doesn't. For most pickers this is fine for registers I have it setup to put instead of copy. So when I'm in terminal window and try to put it inserts into the other window, because put calls close.

liamhennebury avatar Feb 20 '25 16:02 liamhennebury

  • close, will put you in the main editor window. To configure this see (opts.main).
    • this is needed because actions will execute
  • cancel: just puts you back in the previous window

folke avatar Feb 20 '25 17:02 folke