-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
page-up/down doesn’t take into account the number of lines of items in mult-line mode #4069
Comments
Thanks for the report. It should be fixed now on master. |
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
After that, we see all items but some only partially even though they could be fully visible if from that point on, 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. |
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 |
Thanks for the repro. Turns out it's not quite trivial to get it right, especially when considering the different values of |
See 4a85843. The behavior of the actions could still be improved, but at least they don't skip items. |
Thank you! But I’m afraid there are still cases where items are skipped… This looks very tricky. Here is one: { for i in {1..30}; do printf "item $i, line 1\0"; done; for i in {31..34}; do printf "item $i, line 1\n line 2\n line 3\0"; done; for i in {35..90}; do printf "item $i, line 1\0"; done; } | fzf --read0 --reverse --height=28 When iterating
I’m wondering if the problem doesn’t come from the fact that when moving |
Thanks for finding the edge cases and sharing the insight. I think I'm going to have to take a different approach to the problem. I'll let you know of the progress. |
I'd love to hear your feedback on 9c94f9c. Thanks. |
It often works perfectly, but it can still skip items. I noticed it happening when, after doing Here’s an example: { for i in {1..20}; do printf "item $i, line 1\0"; done; printf "item 21, line 1\n line 2\n line 3\n line 4\0"; for i in {22..60}; do printf "item $i, line 1\0"; done; } | fzf --read0 --reverse --height=13 All items have one line, apart from item 21 that has 4 lines. When repeating
In fact, when doing
I suppose this jump leads to the skipped items when doing This would then be a problem with |
I realize now there is no problem with Also, there was a coincidence in my example above that would not be typical: item 21 has 4 (= 1 + 3) lines and the (default) value of With 6 lines for item 21: { for i in {1..20}; do printf "item $i, line 1\0"; done; printf "item 21, line 1\n line 2\n line 3\n line 4\n line 5\n line 6\0"; for i in {22..60}; do printf "item $i, line 1\0"; done; } | FZF_DEFAULT_OPTS= fzf --read0 --reverse --height=13 the 4th step above would still need a jump to maintain (at least) 3 lines below, even if it was below the first line of item 21 rather than below its last line. With |
Thank you very much again, you have great attention to detail. So these page actions are internally translated to a series of |
Here's another take. Please take a look. |
It looks almost perfect! I did not manage to make it skip any item. I still found one imperfection, though, and I’m not entirely sure it could not be exploited to skip an item. In the following example: #!/bin/bash
lines=(
[50]=23
[51]=23
)
print_item() {
num_of_item="$1"
num_of_lines="$2"
printf 'item %3d, line 1' "$num_of_item"
for l in $(seq 2 "$num_of_lines"); do
printf '\n line %s' "$l"
done
printf '\0'
}
for i in {1..120}; do
print_item "$i" "${lines[i]:-1}"
done | FZF_DEFAULT_OPTS='' fzf --read0 --reverse --scroll-off=6 --wrap --height=30 only items 50 and 51 have multiple lines (23 each). If we repeat
So we only got to see 1 line out of 23 of item 51. When repeating
By playing a bit with the values, I think this can only happen when the difference between the total number of lines and the number of lines of the item in question is less than the |
Thank you! For now, I'm going to wrap this issue up here as fzf is no longer skipping items which I think was a bigger problem. The issue you raised above needs to be addressed as well, but I believe it's affecting fewer people and it's not easy to reconcile the different options without making the code too complicated. Anyway, I'll let you know when I revisit this. Thank you again for your help. |
Thank you for your work! The last issue is probably more a problem with |
I’m sorry, but I have bad news: there is still a problem at the very end (the last page), where abnormal behavior can occur, but only when In this example (with no line to wrap): { for i in {1..25}; do printf "item $i, line 1\0"; done; printf 'item 26, line 1\n line 2\n line 3\n line 4\0'; for i in {27..58}; do printf "item $i, line 1\0"; done; } | fzf --read0 --reverse --height=35 --wrap we get the following behaviour:
If we remove |
Nice find, thanks! It looks like a separate issue that I can reproduce with just |
This MR contains the following updates: | Package | Update | Change | |---|---|---| | [junegunn/fzf](https://github.com/junegunn/fzf) | minor | `v0.55.0` -> `v0.56.3` | MR created with the help of [el-capitano/tools/renovate-bot](https://gitlab.com/el-capitano/tools/renovate-bot). **Proposed changes to behavior should be submitted there as MRs.** --- ### Release Notes <details> <summary>junegunn/fzf (junegunn/fzf)</summary> ### [`v0.56.3`](https://github.com/junegunn/fzf/releases/tag/v0.56.3): 0.56.3 [Compare Source](junegunn/fzf@v0.56.2...v0.56.3) - Bug fixes in zsh scripts - fix(zsh): handle backtick trigger edge case ([#​4090](junegunn/fzf#4090)) - revert(zsh): remove 'fc -RI' call in the history widget ([#​4093](junegunn/fzf#4093)) - Thanks to [@​LangLangBart](https://github.com/LangLangBart) for the contributions ### [`v0.56.2`](https://github.com/junegunn/fzf/releases/tag/v0.56.2): 0.56.2 [Compare Source](junegunn/fzf@v0.56.1...v0.56.2) - Bug fixes - Fixed abnormal scrolling behavior when `--wrap` is set ([#​4083](junegunn/fzf#4083)) - \[zsh] Fixed warning message when `ksh_arrays` is set ([#​4084](junegunn/fzf#4084)) ### [`v0.56.1`](https://github.com/junegunn/fzf/releases/tag/v0.56.1): 0.56.1 [Compare Source](junegunn/fzf@v0.56.0...v0.56.1) - Bug fixes and improvements - Fixed a race condition which would cause fzf to present stale results after `reload` ([#​4070](junegunn/fzf#4070)) - `page-up` and `page-down` actions now work correctly with multi-line items ([#​4069](junegunn/fzf#4069)) - `{n}` is allowed in `SCROLL` expression in `--preview-window` ([#​4079](junegunn/fzf#4079)) - \[zsh] Fixed regression in history loading with shared option ([#​4071](junegunn/fzf#4071)) - \[zsh] Better command extraction in zsh completion ([#​4082](junegunn/fzf#4082)) - Thanks to [@​LangLangBart](https://github.com/LangLangBart), [@​jaydee-coder](https://github.com/jaydee-coder), [@​alex-huff](https://github.com/alex-huff), and [@​vejkse](https://github.com/vejkse) for the contributions ### [`v0.56.0`](https://github.com/junegunn/fzf/releases/tag/v0.56.0): 0.56.0 [Compare Source](junegunn/fzf@v0.55.0...v0.56.0) - Added `--gap[=N]` option to display empty lines between items. - This can be useful to visually separate adjacent multi-line items. ```sh ``` ### All bash functions, highlighted declare -f | perl -0777 -pe 's/^}\n/}\0/gm' | bat --plain --language bash --color always | fzf --read0 --ansi --reverse --multi --highlight-line --gap ``` <img width="855" alt="image" src="https://github.com/user-attachments/assets/b3d2eaf2-bf44-4e3a-8d7b-9878629dd9be"> - Or just to make the list easier to read. For single-line items, you probably want to set `--color gutter:-1` as well to hide the gutter. ```sh fzf --info inline-right --gap --color gutter:-1 ``` <img width="855" alt="image" src="https://github.com/user-attachments/assets/113757a1-ccfd-42a6-b946-83533f408e69"> - Added `noinfo` option to `--preview-window` to hide the scroll indicator in the preview window - Bug fixes - Thanks to [@​LangLangBart](https://github.com/LangLangBart), [@​akinomyoga](https://github.com/akinomyoga), and [@​charlievieth](https://github.com/charlievieth) for fixing the bugs </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever MR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this MR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this MR, check this box --- This MR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy40NDAuNyIsInVwZGF0ZWRJblZlciI6IjM3LjQ0MC43IiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJSZW5vdmF0ZSBCb3QiXX0=-->
Checklist
man fzf
)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 topage-down
), if 21 lines (and so 21 items) are visible as in the following example: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:
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.
The text was updated successfully, but these errors were encountered: