fzf icon indicating copy to clipboard operation
fzf copied to clipboard

``--preview-window wrap`` breaks preview scrolling in some condition.

Open fsc0 opened this issue 10 months ago • 1 comments

Checklist

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

Output of fzf --version

0.60.0 (6fa8295a)

OS

  • [x] Linux
  • [ ] macOS
  • [ ] Windows
  • [ ] Etc.

Shell

  • [x] bash
  • [ ] zsh
  • [ ] fish

Problem / Steps to reproduce

I have a text file named preview-scroll-test.txt

Line 1
Line 2
Line 3
Line 4
Line 5
Line 6
Line 7
Line 8
Line 9
Line 10
Line 11
Line 12
Line 13
Line 14
Line 15
Line 16
Line 17
Line 18
Line 19
Line 20
Line 21
Line 22
Line 23 ######################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Line 24
Line 25

And I saved below script like fzf-preview-scroll-test.sh

#!/usr/bin/env bash
: | FZF_DEFAULT_OPTS= fzf \
	--preview-window wrap \
	--preview 'cat /tmp/preview-scroll-test.txt' \
	--bind 'up:preview-page-up,down:preview-page-down'

When I execute the script. Line 24~ is hidden cause of very precise wrapping. And up and down bindings not working.

Image

Let's remove those X phrase on Line 23.

Line 1
Line 2
Line 3
Line 4
Line 5
Line 6
Line 7
Line 8
Line 9
Line 10
Line 11
Line 12
Line 13
Line 14
Line 15
Line 16
Line 17
Line 18
Line 19
Line 20
Line 21
Line 22
Line 23 ######################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################
Line 24
Line 25

Then execute the script again. Line 24 shows up but scrolling still not working.

Image

Now restore those X phase and put a single # at the end of Line 23.

Line 1
Line 2
Line 3
Line 4
Line 5
Line 6
Line 7
Line 8
Line 9
Line 10
Line 11
Line 12
Line 13
Line 14
Line 15
Line 16
Line 17
Line 18
Line 19
Line 20
Line 21
Line 22
Line 23 ######################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX#
Line 24
Line 25

Scrolling is back to work, but Line 24 is gone.

https://github.com/user-attachments/assets/1779dca5-fec4-4232-b57f-e02b4859c2fd

As you can see, to reproducing this issue, user need to prepare a precise text file for their terminal setting. Like increasing Line N and # and X. (Or using fzf's own setting.)

Note. When you adjust the terminal screen size, issue may gone.

EDIT: At the last case, Line 24 wasn't exactly gone, but only can be found with preview-down.

fsc0 avatar Feb 19 '25 10:02 fsc0

Thanks. 0ba0661 will fix the scrollability problem. Please test it and let me know.

fzf --preview-window wrap --preview 'seq $((FZF_PREVIEW_LINES - 2)); yes | head -$((FZF_PREVIEW_COLUMNS + 1)) | xargs | sed "s/ //g"; echo more'

However, 24 not showing on preview-page-down action is not trivial to fix. When we have wrapped lines, we can't no longer just add or subtract the height of the preview window to the scroll offset. Getting it right requires a lot more code as you can see in constrain() function which is for handling that in the list section.

https://github.com/junegunn/fzf/blob/0ba066123e0e1bddbc7def6845135579e0ee2989/src/terminal.go#L6078-L6178

So I'm going to leave it as an open issue (tentatively wontfix).

junegunn avatar Feb 19 '25 23:02 junegunn