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

feature request: API methods for interacting with preview

Open Kyren223 opened this issue 1 year ago • 2 comments

Did you check existing requests?

  • [X] I have searched the existing issues

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 <C-s> 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)

Kyren223 avatar Jul 07 '24 08:07 Kyren223

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()

stevearc avatar Jul 16 '24 07:07 stevearc

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

Kyren223 avatar Jul 16 '24 13:07 Kyren223