--sync: Suppress initial render also when focus event is bound

This commit is contained in:
Junegunn Choi 2024-06-17 17:00:27 +09:00
parent e0ddb97ab4
commit ed12925f7d
No known key found for this signature in database
GPG Key ID: 254BC280FEF9C627
3 changed files with 21 additions and 6 deletions

View File

@ -5,13 +5,15 @@ CHANGELOG
------
- Better cache management and improved rendering for `--tail`
- Improved `--sync` behavior
- When `--sync` is provided, fzf will not render the interface until the initial filtering and associated actions (bound to any of `start`, `load`, or `result`) are complete.
- When `--sync` is provided, fzf will not render the interface until the initial filtering and the associated actions (bound to any of `start`, `load`, `result`, or `focus`) are complete.
```sh
(sleep 1; seq 1000000; sleep 1) | fzf --sync --query 5 --listen --bind start:up,load:up,result:up
# fzf will not render intermediate states
(sleep 1; seq 1000000; sleep 1) |
fzf --sync --query 5 --listen --bind start:up,load:up,result:up,focus:change-header:Ready
```
- GET endpoint is now available from `execute` and `transform` actions (it used to timeout due to lock conflict)
```sh
fzf --listen --bind 'focus:transform-header:curl -s localhost:$FZF_PORT?limit=0 | jq .'
fzf --listen --sync --bind 'focus:transform-header:curl -s localhost:$FZF_PORT?limit=0 | jq .'
```
- Fixed crash when using `--tiebreak=end` with very long items
- Fixed mouse support on Windows

View File

@ -889,10 +889,17 @@ e.g.
.TP
.B "--sync"
Synchronous search for multi-staged filtering. If specified, fzf will launch
the finder only after the input stream is complete.
the finder only after the input stream is complete and the initial filtering
and the associated actions (bound to any of \fBstart\fR, \fBload\fR,
\fBresult\fR, or \fBfocus\fR) are complete.
.RS
e.g. \fBfzf --multi | fzf --sync\fR
e.g. \fB# Avoid rendering both fzf instances at the same time
fzf --multi | fzf --sync
# fzf will not render intermediate states
(sleep 1; seq 1000000; sleep 1) |
fzf --sync --query 5 --listen --bind start:up,load:up,result:up,focus:change-header:Ready\fR
.RE
.TP
.B "--with-shell=STR"

View File

@ -915,7 +915,7 @@ func NewTerminal(opts *Options, eventBox *util.EventBox, executor *util.Executor
}
func (t *Terminal) deferActivation() bool {
return t.initDelay == 0 && (t.hasStartActions || t.hasLoadActions || t.hasResultActions)
return t.initDelay == 0 && (t.hasStartActions || t.hasLoadActions || t.hasResultActions || t.hasFocusActions)
}
func (t *Terminal) environ() []string {
@ -1237,6 +1237,7 @@ func (t *Terminal) UpdateList(merger *Merger) {
t.cy = count - util.Min(count, t.maxItems()) + pos
}
}
needActivation := false
if !t.reading {
switch t.merger.Length() {
case 0:
@ -1244,6 +1245,8 @@ func (t *Terminal) UpdateList(merger *Merger) {
if _, prs := t.keymap[zero]; prs {
t.eventChan <- zero
}
// --sync, only 'focus' is bound, but no items to focus
needActivation = t.suppress && !t.hasResultActions && !t.hasLoadActions && t.hasFocusActions
case 1:
one := tui.One.AsEvent()
if _, prs := t.keymap[one]; prs {
@ -1257,6 +1260,9 @@ func (t *Terminal) UpdateList(merger *Merger) {
t.mutex.Unlock()
t.reqBox.Set(reqInfo, nil)
t.reqBox.Set(reqList, nil)
if needActivation {
t.reqBox.Set(reqActivate, nil)
}
}
func (t *Terminal) output() bool {