Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preserve fzf fuzzy list view? #3779

Closed
5 of 10 tasks
tmpm697 opened this issue May 7, 2024 · 11 comments
Closed
5 of 10 tasks

Preserve fzf fuzzy list view? #3779

tmpm697 opened this issue May 7, 2024 · 11 comments
Labels

Comments

@tmpm697
Copy link

tmpm697 commented May 7, 2024

Checklist

  • I have read through the manual page (man fzf)
  • I have searched through the existing issues
  • For bug reports, I have checked if the bug is reproducible in the latest version of fzf

Output of fzf --version

0.51.0

OS

  • Linux
  • macOS
  • Windows
  • Etc.

Shell

  • bash
  • zsh
  • fish

Problem / Steps to reproduce

i'm using this --preview 'echo $(({n} + 1)) >~/.cache/fzf/my_no_file' \ to save current cursor's position in the list, but i will lose the view of it, how to preserve the view also?

check two images below:
the last view before close fzf:
Screenshot 2024-05-07 at 10 43 14 PM

now after re-open fzf, the view of current line drop to last line:
Screenshot 2024-05-07 at 10 43 26 PM

why i want to preserve the last view? because human brain or my brain will fix thinking the last image of what i see fzf, but when re-open, i am a bit surprise with the view change, the position still correct (10) though.

@kuremu
Copy link
Contributor

kuremu commented May 8, 2024

If you are trying to open fzf at the most recent position after closing, I would suggest something like seq 50 | fzf --bind $'focus:execute-silent(echo $(({n} + 1)) > last.pos)' --bind $'load:transform(echo pos\($(cat last.pos)\))'

@tmpm697
Copy link
Author

tmpm697 commented May 8, 2024

seq 50 | fzf --bind $'focus:execute-silent(echo $(({n} + 1)) > last.pos)' --bind $'load:transform(echo pos($(cat last.pos)))'

it does not load up last post and not keep the view

@kuremu
Copy link
Contributor

kuremu commented May 8, 2024

If you mean you want to reopen fzf with 10 still selected, and also 11 and 12 still visible at the bottom of the list, I don't think there is functionality for this. The scrolling and view position is sorted out automatically by pos(). You might find --scroll-off=n useful, which will at least keep a buffer of n items between the top/bottom edges of the list and the cursor.

@tmpm697
Copy link
Author

tmpm697 commented May 8, 2024

If you mean you want to reopen fzf with 10 still selected, and also 11 and 12 still visible at the bottom of the list, I don't think there is functionality for this. The scrolling and view position is sorted out automatically by pos(). You might find --scroll-off=n useful, which will at least keep a buffer of n items between the top/bottom edges of the list and the cursor.

yeah, --scroll-off=LINES helped but it feel less natural than usual.

and why u suggest save and restore pos with this? seq 50 | fzf --bind $'focus:execute-silent(echo $(({n} + 1)) > last.pos)' --bind $'load:transform(echo pos\($(cat last.pos)\))' --> i tried and it does not work, pos is saved to file but cursor not restored at last pos.

@kuremu
Copy link
Contributor

kuremu commented May 9, 2024

and why u suggest save and restore pos with this? seq 50 | fzf --bind $'focus:execute-silent(echo $(({n} + 1)) > last.pos)' --bind $'load:transform(echo pos\($(cat last.pos)\))' --> i tried and it does not work, pos is saved to file but cursor not restored at last pos.

Sorry didn't notice you were using zsh. This looks like it works:

seq 50 | fzf --bind 'focus:execute-silent(echo $(({n} + 1)) > last.pos)' --bind 'load:transform:echo pos\($(cat last.pos)\)'

@tmpm697
Copy link
Author

tmpm697 commented May 9, 2024

seq 50 | fzf --bind 'focus:execute-silent(echo $(({n} + 1)) > last.pos)' --bind 'load:transform:echo pos($(cat last.pos))'

ty, so via --bind is more preferred than via --preview to save/restore pos is what u mean?

@kuremu
Copy link
Contributor

kuremu commented May 9, 2024

ty, so via --bind is more preferred than via --preview to save/restore pos is what u mean?

Yeah, specifically --bind 'focus:... for saving and --bind 'load:... for loading. But there are quite a few ways you could do it. Check man fzf AVAILABLE KEYS and AVAILABLE EVENTS for what you can bind to, and AVAILABLE ACTIONS for what can be performed on a bind.

@tmpm697
Copy link
Author

tmpm697 commented May 18, 2024

@junegunn @LangLangBart any idea for this issue?

@junegunn
Copy link
Owner

What exactly are you trying to implement here?

fzf doesn't support persisting and restoring its internal states between processes, because of its asynchronous nature and because there are just too many dynamic states that affect the user interface. If you want to quickly come back to fzf after running some other interactive tasks, use execute action.

@tmpm697
Copy link
Author

tmpm697 commented May 19, 2024

i just realized that this feature may need to bring a daemon and db to persist some states which is not standalone exe fzf can solve.

@tmpm697
Copy link
Author

tmpm697 commented May 20, 2024

for someone who stumble to this issue later, we can save last post with fzf and restore it later, then i wonder if we can able to save the last top line pos (below header if has) and the bottom one --> so we can restore the last pos relative to one of two top and bottom pos.

this theoretically possible, when we restore the last pos, say we can make it relative (last pos + last bottom) = current relative pos. or (last pos + last top) = relative pos.

@junegunn is that possible?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants