fish: Fixes and improvements to CTRL-R#4703
Conversation
|
I was planning to also add EDIT: This will add extra space between the prefix and the command, though. There is also an issue when wrapping is enabled by pressing echo 1\tfoo\n2\t(string repeat -n 100 'bar ') | fzf --freeze-left=1 --no-wrapThe space between |
|
Thanks a lot! This looks like a solid improvement. One question: Did you intend to color the first word of a command entry red? Should we append
So I see you appropriately adoped the
I think it's a good suggestion, though I wonder how we should notify the user when that happens.
This was by design to simplify the implementation. Being able to scroll into the middle of a wrapped line brings complexity. For example, we would have to recalculate the display offset whenever the window is resized. Vim has the same limitation, so I thought it would be acceptable for a "preview" window.
Ah, it's a bug. Thanks. I'll look into it.
Another bug! Thanks!
Sounds like a plan. |
This didn't happen for me - |
02892b8 to
041578a
Compare
Fixes bugs reported in #4703: * Clamp followOffset return value to avoid going past the end of lines * Account for t.previewed.filled when determining scrollability
I see, I'm not a fish user, so fortunately I had zero configuration :) The two commits I pushed to master should fix the issues you reported. Please take a look. |
I tested them and they work great. Thanks! |
|
Test failure seems unrelated. Let me see. Confirmed unrelated. It can fail on small screens. Let me fix the test case on master. |
Hmm, what do you think about making diff --git a/src/tokenizer.go b/src/tokenizer.go
index 25448f59..a143636c 100644
--- a/src/tokenizer.go
+++ b/src/tokenizer.go
@@ -161,7 +161,7 @@ func awkTokenizer(input string) ([]string, int) {
end := 0
for idx := 0; idx < len(input); idx++ {
r := input[idx]
- white := r == 9 || r == 32
+ white := unicode.IsSpace(rune(r))
switch state {
case awkNil:
if white {
@@ -218,6 +218,10 @@ func Tokenize(text string, delimiter Delimiter) []Token {
return withPrefixLengths(tokens, 0)
}
+func isSpace(r rune) bool {
+ return r != '\n' && unicode.IsSpace(r)
+}
+
// StripLastDelimiter removes the trailing delimiter and whitespaces
func StripLastDelimiter(str string, delimiter Delimiter) string {
if delimiter.str != nil {
@@ -231,7 +235,7 @@ func StripLastDelimiter(str string, delimiter Delimiter) string {
}
}
}
- return strings.TrimRightFunc(str, unicode.IsSpace)
+ return strings.TrimRightFunc(str, isSpace)
}
func GetLastDelimiter(str string, delimiter Delimiter) string {It won't affect most use cases. EDIT: Well, there can be cases where this is not desirable. # A new line character after the hash used to be stripped
git log -z --format='%H%n%s%n%b' | fzf --reverse --read0 --gap --highlight-line --with-nth '{1} => {2..}' |
That would work for the script. But it couldn't be used for other cases, for example a field containing filenames, because they could have trailing spaces.
I think that it would make sense to keep it when |
|
Thanks for the input. Let me think a bit more about it. That said, I think this PR is great and already ready as it is. But since it's mentioning the new feature on the README page, we may delay merging it, or merge it to the |
|
How about this approach: when This actually aligns better with the current man page description of However, while this sounds reasonable, it breaks several contracts: I'm not sure how may users rely on the current behavior though. # Changed behavior
echo 'foo, bar , baz' | fzf --delimiter , --with-nth '{2} // {1} // {3} // {1}'
# A potential workaround
echo 'foo, bar , baz' | fzf --delimiter "\s*,\s*" --with-nth '{2} // {1} // {3} // {1}' |
|
I decided to go that route. I think you can now simplify that part by rebasing onto the latest master. |
Fixes: - Commands with trailing newlines - Very long previews Improvements: - SHIFT-DELETE performance - Bind ALT-T: cycle command prefix (timestamp, date/time, none) - Set comment color for prefix
|
Thanks, I made the final change. I also switched the merge branch to |
|
Thanks for the great work! |
Fixes: - Commands with trailing newlines - Very long previews Improvements: - SHIFT-DELETE performance - Bind ALT-T: cycle command prefix (timestamp, date/time, none) - Set comment color for prefix
Fixes: - Commands with trailing newlines - Very long previews Improvements: - SHIFT-DELETE performance - Bind ALT-T: cycle command prefix (timestamp, date/time, none) - Set comment color for prefix
Fixes: - Commands with trailing newlines - Very long previews Improvements: - SHIFT-DELETE performance - Bind ALT-T: cycle command prefix (timestamp, date/time, none) - Set comment color for prefix
Fixes: - Commands with trailing newlines - Very long previews Improvements: - SHIFT-DELETE performance - Bind ALT-T: cycle command prefix (timestamp, date/time, none) - Set comment color for prefix
This MR contains the following updates: | Package | Update | Change | |---|---|---| | [junegunn/fzf](https://github.com/junegunn/fzf) | minor | `v0.70.0` → `v0.71.0` | 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.71.0`](https://github.com/junegunn/fzf/releases/tag/v0.71.0): 0.71.0 [Compare Source](junegunn/fzf@v0.70.0...v0.71.0) *Release highlights: <https://junegunn.github.io/fzf/releases/0.71.0/>* - Added `--popup` as a new name for `--tmux` with Zellij support - `--popup` starts fzf in a tmux popup or a Zellij floating pane - `--tmux` is now an alias for `--popup` - Requires tmux 3.3+ or Zellij 0.44+ - Cross-reload item identity with `--id-nth` - Added `--id-nth=NTH` to define item identity fields for cross-reload operations - When a `reload` is triggered with tracking enabled, fzf searches for the tracked item by its identity fields in the new list. - `--track --id-nth ..` tracks by the entire line - `--track --id-nth 1` tracks by the first field - `--track` without `--id-nth` retains the existing index-based tracking behavior - The UI is temporarily blocked (prompt dimmed, input disabled) until the item is found or loading completes. - Press `Escape` or `Ctrl-C` to cancel the blocked state without quitting - Info line shows `+T*` / `+t*` while searching - With `--multi`, selected items are preserved across `reload-sync` by matching their identity fields - Performance improvements - The search performance now scales linearly with the number of CPU cores, as we dropped static partitioning to allow better load balancing across threads. ``` === query: 'linux' === [all] baseline: 21.95ms current: 17.47ms (1.26x) matches: 179966 (12.79%) [1T] baseline: 179.63ms current: 180.53ms (1.00x) matches: 179966 (12.79%) [2T] baseline: 97.38ms current: 90.05ms (1.08x) matches: 179966 (12.79%) [4T] baseline: 53.83ms current: 44.77ms (1.20x) matches: 179966 (12.79%) [8T] baseline: 41.66ms current: 22.58ms (1.84x) matches: 179966 (12.79%) ``` - Improved the cache structure, reducing memory footprint per entry by 86x. - With the reduced per-entry cost, the cache now has broader coverage. - Shell integration improvements - bash: CTRL-R now supports multi-select and `shift-delete` to delete history entries ([#​4715](junegunn/fzf#4715)) - fish: - Improved command history (CTRL-R) ([#​4703](junegunn/fzf#4703)) ([@​bitraid](https://github.com/bitraid)) - Rewrite completion script (SHIFT-TAB) ([#​4731](junegunn/fzf#4731)) ([@​bitraid](https://github.com/bitraid)) - Increase minimum fish version requirement to 3.4.0 ([#​4731](junegunn/fzf#4731)) ([@​bitraid](https://github.com/bitraid)) - `GET /` HTTP endpoint now includes `positions` field in each match entry, providing the indices of matched characters for external highlighting ([#​4726](junegunn/fzf#4726)) - Allow adaptive height with negative value (`--height=~-HEIGHT`) ([#​4682](junegunn/fzf#4682)) - Bug fixes - `--walker=follow` no longer follows symlinks whose target is an ancestor of the walker root, avoiding severe resource exhaustion when a symlink points outside the tree (e.g. Wine's `z:` → `/`) ([#​4710](junegunn/fzf#4710)) - Fixed AWK tokenizer not treating a new line character as whitespace - Fixed `--{accept,with}-nth` removing trailing whitespaces with a non-default `--delimiter` - Fixed OSC8 hyperlinks being mangled when the URL contains unicode characters ([#​4707](junegunn/fzf#4707)) - Fixed `--with-shell` not handling quoted arguments correctly ([#​4709](junegunn/fzf#4709)) - Fixed child processes not being terminated on Windows ([#​4723](junegunn/fzf#4723)) ([@​pjeby](https://github.com/pjeby)) - Fixed preview scrollbar not rendered after `toggle-preview` - Fixed preview follow/scroll with long wrapped lines - Fixed tab width when `--frozen-left` is used - Fixed preview mouse events being processed when no preview window exists - zsh: Fixed history widget when `sh_glob` option is on ([#​4714](junegunn/fzf#4714)) ([@​EvanHahn](https://github.com/EvanHahn)) </details> --- ### Configuration 📅 **Schedule**: (UTC) - 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:eyJjcmVhdGVkSW5WZXIiOiI0My4xMDQuMSIsInVwZGF0ZWRJblZlciI6IjQzLjEwNC4xIiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJSZW5vdmF0ZSBCb3QiLCJhdXRvbWF0aW9uOmJvdC1hdXRob3JlZCIsImRlcGVuZGVuY3ktdHlwZTo6bWlub3IiXX0=-->
A few more changes to command history:
SHIFT-DELETE:history deleteonce and passing the selected items via command substitution.ENTER(instead ofALT-ENTER).\␊don't lose the trailing newline and cause a following selected command to be shown as a continuation of the previous one.multi, so it will be triggered when selecting the very last command (which is not triggered byfocus).ALT-T(uses the newchange-with-nthoption).datecommand for conversion.$fish_color_comment, so it is easier distinguished from the actual command.\␊:accept-nthstrips the trailing newline, but it is important to keep it when inserting multiple commands. Consider the following example: The commandsrm -rf ~/trash \␊(1) andls ~/(2) are selected for insertion. What will be inserted instead, is a singlerm -rfcommand with a line break after~/trashand the last token being/~(will wipe the home directory!). For that reason, abecomeaction is bind toENTER, that reads the selected commands from a temporary file (for not hitting the single argument length limit) created with thesflag, and then having to manually delete the file (since it's not possible for fzf to remove the file). This is unnecessary for most cases though, and it would be much better ifaccept-nth(and maybe alsowith-nth) had a flag to keep trailing whitespace characters. Let me know what you think.$FZF_CTRL_R_OPTS.While working on this, I noticed a couple of issues that I think are worth mentioning:
becomecommand may fail to execute and won't return to the shell prompt: Because the command is passed to the shell as a single argument, it is possible to exceed the 128K limit ofMAX_ARG_STRLEN. This is not so serious forpreviewortransform(will returnargument list too longerror), but forbecomethe shell will be left in a broken state. This doesn't affect the script, but maybe fzf should not attempt to execute the command if its final total length is longer than128 * 1024 - 1characters.If
followis also set, it scrolls too far down and no part of the line is visible (notice the info shows2/1).Scrolling up, will scroll to the beginning of the line, and the ability to scroll again is lost (it's not possible to view the end of the line).