junegunn / fzf

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

page-up/down doesn’t take into account the number of lines of items in mult-line mode #4069

Open vejkse opened 2 days ago

vejkse commented 2 days ago

Checklist

Output of fzf --version

0.56 (devel)

OS

Shell

Problem / Steps to reproduce

With one-line items, when doing PgUp (bound by default to page-up) and PgDn (bound by default to page-down), if 21 lines (and so 21 items) are visible as in the following example:

for i in {01..99}; do echo -ne "item $i\0"; done | fzf --read0 --reverse --height=23

each movement one page up or down goes 20 lines (and so 20 items) up or down the list, as one would expect.

But in the following example with 2-line items, where 21 lines (and so 10.5 items) are visible:

for i in {01..99}; do echo -ne "item $i, line 1\nitem $i, line 2\0"; done | fzf --read0 --reverse --height=23

each movement one page up or down doesn’t go about 20 lines up or down the list, as one would expect, but 20 items (so 40 lines) up or down the list, so that each time we go up or down, we skip about 10 items.

junegunn commented 1 day ago

Thanks for the report. It should be fixed now on master.

vejkse commented 1 day ago

Thank you!

But I think it doesn’t work in all cases. I should have made an example with variable length, like this one where each item n > 1 has ⌈n/2⌉ + 1 lines:

for i in {1..99}; do printf "item $i, line %d\n" $(seq 1 $((i/2))); echo -ne "item $i, line $((i/2+1))\0"; done | fzf --read0 --reverse --height=23

Here is how it goes when repeating page-down:

  1. Items 1-7 are fully visible and 1 line of item 8.
  2. Items 5-9 are fully visible.
  3. Items 11-13 are fully visible and 1 line of item 14 — so item 10 was jumped over.
  4. Items 14-15 are fully visible and 5 lines of item 16.
  5. Items 18-19 are fully visible and 1 line of item 20 — so item 17 was jumped over.

After that, we see all items but some only partially even though they could be fully visible if from that point on, page-down became equivalent to down.

Of course, once we get to items that have too many lines to be shown in that limited height, they will never be fully visible.

vejkse commented 1 day ago

Even a uniform 3-line case has a little problem, like this one:

for i in {01..99}; do echo -ne "item $i, line 1\nitem $i, line 2\nitem $i, line 3\0"; done | fzf --read0 --reverse --height=22

When repeating page-down, after the initial steps, only two lines of the last item on each page are visible, but the full item is not visible on the next page. One could argue that this is acceptable, I suppose.