stevearc / oil.nvim

Neovim file explorer: edit your filesystem like a buffer
MIT License
3.5k stars 99 forks source link

feature request: API methods for interacting with preview #443

Open Kyren223 opened 4 weeks ago

Kyren223 commented 4 weeks ago

Did you check existing requests?

Describe the feature

Add 2 new API functions (names r just an example) is_preview_open() - returns a boolean close_preview() - closes the preview (might already exist?)

Provide background

If I have preview on and then open a split (with C-s for example) the preview stays open, so I'd like to write a little function that when I press it checks if there is a preview, if there is, closes it, and then opens the new split

What is the significance of this feature?

nice to have

Additional details

Would also love to see #339 gets implemented as I'd need it as well for what I intend to do (although there are workarounds for doing it)

stevearc commented 2 weeks ago

Oil uses :help previewwindow for the preview window, so you can do this yourself pretty easily. Here's how oil gets the preview window internally

https://github.com/stevearc/oil.nvim/blob/9e5eb2fcd1dfee2ff30c89273ffff179e42034b9/lua/oil/util.lua#L661-L668

You can use this directly if you want, but there's no API contract so the method may be removed or renamed in the future. You could copy the logic to your own config as well, since it's pretty short and simple.

To close the preview window, just do vim.cmd.pclose()

Kyren223 commented 2 weeks ago

Ah thanks, I'll just copy over that code snippet and use that.