junegunn / fzf

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

When sending reload(...) + preview(...) during the same event, the preview is reset #3723

Closed noahmayr closed 4 months ago

noahmayr commented 4 months ago

Checklist

Output of fzf --version

0.49.0 (brew)

OS

Shell

Problem / Steps to reproduce

Reproduction:

  1. Run the following example
    SHELL=/bin/sh LIST="a\nb\nc" fzf --preview 'echo {}'  --bind 'start:reload(echo $LIST)' --bind 'ctrl-p:reload(echo $LIST)+preview(echo "Hello World")
  2. Press ctrl-p to switch to a temporary preview showing "Hello World"

Expected: The list is reloaded and the preview shows "Hello World" and goes back to the configured preview when navigating through the list

Actual: The list is reloaded, the preview quickly flashes "Hello World" before showing the preview configured by --preview

junegunn commented 4 months ago

Both reload and preview actions run asynchronously, so there is no guarantee that they finish in the specified order.

To give a better example:

echo alice | fzf --preview 'echo Hello {}' --bind 'space:reload(sleep 1; echo bob)+preview(echo Hi {})'

I'm not sure what you're trying to achieve with the actions, but it looks like you need a different strategy.