ibhagwan / fzf-lua

Improved fzf.vim written in lua
MIT License
2.31k stars 150 forks source link

Possible to expand FZF window dynamically? #611

Closed egargan-ft closed 1 year ago

egargan-ft commented 1 year ago

Description

I've been looking through the plugin's help pages and source code, but I don't think there's an easy way of changing an active FZF window's height and width with an action or keymap.

I'd like to use the "toggle-preview" action to show and hide a file preview in a pretty small FZF window. Doing this at the moment, when the preview's visible, it makes both the results pane and the preview pane too cramped.

Is there a function I can call in some keymap handler that'll let me increase/decrease the overall width/height of the window, while preserving window state (search term, selection, etc.)?

If no, would it be easy to implement? I'm happy to have a go at this myself, but looking at the win.lua file, it's not obvious how I would.

ibhagwan commented 1 year ago

The builtin previewer is one part where IMO there is more work to be done for the API to be as clear and easy as fzf_exec and that’s part of the reason I haven’t expanded on it in the wiki as one day I’d like to make change the API not worry too much about breaking functionality for existing users.

That said it is possible to do what you want with a bit of custom code, in fact, that’s exactly what the preview rotation does (F5|F6) does, it changes the layout and toggles the preview to match the new layout, the same code can be applied to making the preview smaller/larger (as opposed to a clockwise toggle).

If you wish to do so, dup the below code and set the new winopts to whatever you like: https://github.com/ibhagwan/fzf-lua/blob/292de730ebbd3834e87f864c8c4115dc1035db37/lua/fzf-lua/win.lua#L1144-L1171

You can then map your custom function to a keybind using the winopts.on_create callback.

ibhagwan commented 1 year ago

If you need access to the fzf-lua window object (instead of _self) you can call require'fzf-lua'.utils.fzf_winobj()

ibhagwan commented 1 year ago

Closing, feel free to reopen if you need more help.

egargan commented 1 year ago

Thank you! I'll give that a try, looks easy enough.