junegunn / fzf

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

[BUG?] `reload` resets selections #2441

Open NightMachinery opened 3 years ago

NightMachinery commented 3 years ago

Info

Problem / Steps to reproduce

I use change:reload to update the inputs with newly arrived candidates. It works great, except that the reload clears the previous selections (i.e., it unmarks everything). The expected (to me) behavior is to keep the selected items, even if they are NOT present in the new input.

junegunn commented 3 years ago

Actually, that's the intended behavior and we have a test case for it.

https://github.com/junegunn/fzf/commit/05b5f3f845a88e9b034f3302bb50672fc5b7f8c7

I didn't like keeping the previous selections because once they're gone from the list, there's no direct way to un-select them or to see which ones are currently selected.

What is your actual use case?

NightMachinery commented 3 years ago

@junegunn

What is your actual use case?

I am trying to integrate my fzf functions with GUI programs; For example, I have a clipboard manager implemented via fzf, and I want to see this fzf “popup” when I press CMD+V. I achieve this by assigning the hotkey CMD+v to a (half-transparent) terminal window that is running the fzf program in a loop. This loop is basically running the fzf function that displays the current database of clipboard history, then hides the terminal window upon user selection, and pastes the results.

The problem is that it’s hard to know when the terminal window has gotten focus, so the fzf function is called immediately after one “session” finishes and the window is hidden. This results in the fzf input being stale.

Refreshing the input periodically is not a good solution as it might do the reload in the middle of a “session.”

I currently wait for the user’s first typed char to start fzf, but this is not ideal as I can’t see the candidates before typing that single char.

once they're gone from the list, there's no direct way to un-select them or to see which ones are currently selected.

Can’t we just keep any candidate that has been selected in the list forever? In my use case, the new input only adds new candidates, and so mapping could also be done, but the complexity doesn’t seem necessary.

pyglot commented 2 years ago

First: Thank you so much for fzf! It's really amazingly great!

I have a use-case where I am using fzf -m.

The use-case is to select multiple files and/or directories and yank them back to the command-line. I have set key bindings Ctrl+F and Ctrl+D to use reload to swap between filters for Files only or Directories only, but the selection is lost when running reload.

Here's a bash oneliner that shows the use of fzf in my use-case:

fdfind --color always | fzf --ansi --prompt '>' -m --header 'Select ^O/^P, File/Dir ^F/^D' \
 --bind 'ctrl-d:reload(fdfind --color always -t d)' --bind 'ctrl-f:reload(fdfind --color always -t f)' \
 --bind ctrl-o:select-all --bind ctrl-p:deselect-all

Some quick thoughts from me are:

FilipeBento commented 1 month ago

This would be amazing if implemented. Keeping my selection between different reloads would help greatly! I also understand it might not be easy to implement, though.