From d8bfb6712d514fd6715135fd0e60df188831b566 Mon Sep 17 00:00:00 2001 From: Junegunn Choi Date: Sat, 20 Apr 2024 14:40:48 +0900 Subject: Remove invalid 'result' event when using --sync option When the search for the initial query doesn't finish immediately fzf would trigger an invalid 'result' event for an empty query. seq 100 | fzf --query 99 --bind result:accept --sync # Prints 99 seq 1000000 | fzf --query 99 --bind result:accept --sync # Should print 99, but fzf would print 1 --- man/man1/fzf.1 | 2 +- src/core.go | 5 ++--- src/terminal.go | 4 ++-- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/man/man1/fzf.1 b/man/man1/fzf.1 index 3af1a1e8..0d131c7a 100644 --- a/man/man1/fzf.1 +++ b/man/man1/fzf.1 @@ -812,7 +812,7 @@ e.g. .TP .B "--sync" Synchronous search for multi-staged filtering. If specified, fzf will launch -ncurses finder only after the input stream is complete. +the finder only after the input stream is complete. .RS e.g. \fBfzf --multi | fzf --sync\fR diff --git a/src/core.go b/src/core.go index 3d84c733..ec137698 100644 --- a/src/core.go +++ b/src/core.go @@ -298,8 +298,7 @@ func Run(opts *Options, version string, revision string) { total = count terminal.UpdateCount(total, !reading, value.(*string)) if opts.Sync { - opts.Sync = false - terminal.UpdateList(PassMerger(&snapshot, opts.Tac, snapshotRevision)) + terminal.UpdateList(PassMerger(&snapshot, opts.Tac, snapshotRevision), false) } if heightUnknown && !deferred { determine(!reading) @@ -384,7 +383,7 @@ func Run(opts *Options, version string, revision string) { determine(val.final) } } - terminal.UpdateList(val) + terminal.UpdateList(val, true) } } } diff --git a/src/terminal.go b/src/terminal.go index 0519836f..b885ce25 100644 --- a/src/terminal.go +++ b/src/terminal.go @@ -1067,7 +1067,7 @@ func (t *Terminal) UpdateProgress(progress float32) { } // UpdateList updates Merger to display the list -func (t *Terminal) UpdateList(merger *Merger) { +func (t *Terminal) UpdateList(merger *Merger, triggerResultEvent bool) { t.mutex.Lock() prevIndex := minItem.Index() reset := t.revision != merger.Revision() @@ -1118,7 +1118,7 @@ func (t *Terminal) UpdateList(merger *Merger) { t.eventChan <- one } } - if t.hasResultActions { + if triggerResultEvent && t.hasResultActions { t.eventChan <- tui.Result.AsEvent() } } -- cgit v1.2.3