Skip to content

Commit

Permalink
Remove invalid 'result' event when using --sync option
Browse files Browse the repository at this point in the history
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
  • Loading branch information
junegunn committed Apr 20, 2024
1 parent f864f8b commit d8bfb67
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 6 deletions.
2 changes: 1 addition & 1 deletion man/man1/fzf.1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 2 additions & 3 deletions src/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -384,7 +383,7 @@ func Run(opts *Options, version string, revision string) {
determine(val.final)
}
}
terminal.UpdateList(val)
terminal.UpdateList(val, true)
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/terminal.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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()
}
}
Expand Down

0 comments on commit d8bfb67

Please sign in to comment.