junegunn / fzf

:cherry_blossom: A command-line fuzzy finder
https://junegunn.github.io/fzf/
MIT License
64.58k stars 2.38k forks source link

[Feature Request] Add action to stop Preview window from updating on focus change. #3303

Open alpiccioni opened 1 year ago

alpiccioni commented 1 year ago

Info

Ask

An action to enable/disable/toggle the preview not refreshing when focus is changed.

Use-Case

I have a complicated fzf program (github.com/google/purr) where the preview is initially set to be a set of instructions, unrelated to the focused string. Since the preview is sticky, the user can keep the instructions on screen while using the program.

This works mostly well. However, if the instructions overscroll the preview, a focus change will force the preview back to the top, which leads to reading the instructions to be difficult.

This feature would allow previews that are unrelated to the focused string to be displayed.

Another usecase would be to use the preview as a second viewing screen for a program unrelated to the query; this may be useful for showing a slow-moving, unrelated log file in a preview, or showing a resource monitor or other tangential program.

There are also programs I wish to show in a preview on a focused string, but not run every time I switch focus. I may, for example, wish to send a query to ChatGPT or a curl search request for what a certain focused string returns, but I don't want to do this every time I change focus, as the latency is too high. I may want to instead bind a hotkey to refresh the preview, and allow independent scrolling.

junegunn commented 1 year ago

You can start fzf without --preview option, and run the initial preview command on start event, and set up the proper previewer later like so.

fzf --bind 'start:preview(seq 1000)' --bind 'space:change-preview:cat {}'

There is a limitation though, the initial preview window will be lost when you resize the window.

alpiccioni commented 1 year ago

Hey junegunn,

That does indeed stop the preview from scrolling, which is useful! However, setting the preview at start seems to have certain eccentricities which degrade UX.

Say I use the following command:

fzf  --bind 'start:preview(seq 1000)' --bind 'space:change-preview(seq 1000)' --bind 'p:toggle-preview'

When I initially enter the program, I can scroll around the window without the preview window shifting. However, if I press p twice, the preview window reappears as blank without saving the contents.

Additionally, if I press space, the preview window reload, but this doesn't maintain the same behaviour, and now reset the preview window whenever the user scrolls in the main window.

This would make it tricky to implement, since the user can't dismiss or change the preview window without the start behaviour breaking. For example, if they had an instruction window open, and there was another preview window that interacted with the main window, or they wanted to dismiss the instructions temporarily to see more of the main window, both of these actions would return to the previous, undesirable behaviour.

Thanks!