Dynamically resizing the float layout before preview toggle #1115
-
Hello @ibhagwan, i am looking to resize a floating layout, doubling the height, that would allow me keep the same height for the list of items below the preview, instead of halving it, when preview is on, i have configured the preview to take up 50% of the float size when enabled Looking at the The same source below works just fine for local function toggle_preview_win()
local preview = fzf_lua.win.__SELF()
local winid = preview.fzf_winid
local hidden = preview.preview_hidden
local height = vim.api.nvim_win_get_height(winid)
height = hidden and height * 2 or height / 2
vim.api.nvim_win_set_height(winid, math.ceil(height))
preview.toggle_preview()
end |
Beta Was this translation helpful? Give feedback.
Replies: 6 comments 5 replies
-
@asmodeus812, could the behavior added in #721 be relevant in this case? require("fzf-lua").setup({
previewers = { builtin = { toggle_behavior = "extend" } },
}) |
Beta Was this translation helpful? Give feedback.
-
The issue you’re facing is that
You’re correct, this will most likely break and cause all kinds of other unintended behaviors. I think the best way to address your issue is to use code similar to the preview rotation code, you hijack the Lines 1272 to 1279 in b5e08be |
Beta Was this translation helpful? Give feedback.
-
That is correct because there is no preview window/buffer as the preview is handled by fzf in the terminal.
I’m not sure what your code replaces but if it doesn’t regress any existing use case and it solves your issue make a PR and I will accept it. In general the window/previewer code has been through a journey, it started as just a single window manager with only fzf native previewers, then the neovim “builtin” previewer was added on top, then splits and then fzf-tmux. Due to the above there is a lot of improvement to be had in that part of the code, I would’ve loved for it to be split into classes per use-case, one for splits, one for native, etc and have a better designed relationship with the previewer class, optimally I’d like to users to be able to supply their window creation class via an API for integrations like nui, etc. As you can imagine this would take time and effort and as of now no real benefit as the code most of the time works flawlessly so I haven’t gotten to it and don’t know when I will. |
Beta Was this translation helpful? Give feedback.
-
Currently this is the first branch of the toggle_preview, however its wrong if preview.preview_hidden and preview:validate_preview() then
preview:close_preview()
redraw_main()
end
if preview.preview_hidden then
if preview:validate_preview() then
preview:close_preview()
end
redraw_main()
end There is an obvious short circuit, in the code that creates the preview & border windows, which pretty much says it all, preview windows are not created for native ones, which is expected, since those are delegated to fzf if not self.previewer_is_builtin or self.preview_hidden then return end Can we at least adjust toggle_preview as suggested above ? |
Beta Was this translation helpful? Give feedback.
-
Why would we want to redraw main when no change is required to the fzf terminal window? With native previews, the toggle happens internally inside fzf, this function doesn’t even get called for native previewers, nor does the binding for this exist for native previewers: Lines 44 to 51 in 7ecc8e3 As you can see from above only help and full screen key maps are set for native previews, therefore the entire discussion about this function is irrelevant (in the context of native previewers). You already have the win object from If you need an internal win function to be exposed let me know and I’ll make it part of the object. |
Beta Was this translation helpful? Give feedback.
-
If you’re using native previewer this would require a different approach, why not add a postfix to your acrion You can see how I use these in the recently added Lines 356 to 366 in 7ecc8e3 |
Beta Was this translation helpful? Give feedback.
Why would we want to redraw main when no change is required to the fzf terminal window? With native previews, the toggle happens internally inside fzf, this function doesn’t even get called for native previewers, nor does the binding for this exist for native previewers:
fzf-lua/lua/fzf-lua/win.lua
Lines 44 to 51 in 7ecc8e3