Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature request: API methods for interacting with preview #443

Open
1 task done
Kyren223 opened this issue Jul 7, 2024 · 2 comments
Open
1 task done

feature request: API methods for interacting with preview #443

Kyren223 opened this issue Jul 7, 2024 · 2 comments
Labels
enhancement New feature or request

Comments

@Kyren223
Copy link

Kyren223 commented Jul 7, 2024

Did you check existing requests?

  • 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 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 Kyren223 added the enhancement New feature or request label Jul 7, 2024
@stevearc
Copy link
Owner

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

oil.nvim/lua/oil/util.lua

Lines 661 to 668 in 9e5eb2f

---@return nil|integer
M.get_preview_win = function()
for _, winid in ipairs(vim.api.nvim_tabpage_list_wins(0)) do
if vim.api.nvim_win_is_valid(winid) and vim.wo[winid].previewwindow then
return winid
end
end
end

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 stevearc added the question Further information is requested label Jul 16, 2024
@stevearc stevearc changed the title feature request: feature request: API methods for interacting with preview Jul 16, 2024
@Kyren223
Copy link
Author

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

@github-actions github-actions bot removed the question Further information is requested label Jul 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants