rmagatti / goto-preview

A small Neovim plugin for previewing definitions using floating windows.
Apache License 2.0
843 stars 28 forks source link

[FEATURE] Close Currently focussed preview window with q #121

Open Kruziikrel13 opened 3 months ago

Kruziikrel13 commented 3 months ago

Is your feature request related to a problem? Please describe. When I have a stack of preview windows open I'd like to be able to quickly close them one by one starting from the top window / currently focussed preview window (Last opened) using a keybind like 'q'

Describe the solution you'd like A close keybind option to close the top most preview window.

Describe alternatives you've considered I've tried assigning keybinds to the preview windows themselves with the post open hook however it only seems to work the first time I press q and then it will not close any of the remaining open preview windows.

rmagatti commented 3 months ago

Yeah the issue with this is that there's no way to set keymaps for specific windows only currently in vim/neovim. https://github.com/vim/vim/issues/9339 https://github.com/neovim/neovim/issues/16263

One could set a buf keymap and then unset it when the last window for that buffer closes, the issue with that approach would be that the mapping would also apply to the original window with the same buf. I suppose one could set it so that if there's only one window for a given buf, remove the mapping. It's just a lot of playing around with hooks and vim's apis to get the exact behaviour you want.

I personally just use the same mapping I already have to close windows/buffers <leader>q and that works fine and goes in order of opened preview windows as one would expect

Kruziikrel13 commented 3 months ago

Yeah, I see what you mean, I think I faced the same problem you're describing here as I tried to fully implement this on my own, but there was far too many issues to have to try and catch in mapping and unmapping the keybinds due to the scope at which they get applied.