Add 'wait' action to block until search completion (#4825)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Blocks execution of subsequent actions until the current search completes, so motion actions operate on the complete result set. # Move to the best match only after the search is done fzf --bind 'start:change-query(foo)+wait+best' - Blocks when a search is in progress, will be triggered by preceding actions, or the query was edited in the same binding; no-op otherwise - Initial input load counts as a search in progress, so 'start:wait' blocks until the input is fully loaded and searched - User input ignored while blocked, including --expect keys; keys bound to abort/cancel cancel the wait and discard pending actions instead - Actions deferred by the wait survive across nested lists (trigger chords) and cancel/re-arm chains - Debounced feedback after 200ms: dimmed prompt, hidden cursor, and (..) on the info line
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
6 files+303 added−19 removed
- tests:+77 added−0 removed
- other:+226 added−19 removed
Provenance
- Commit
8ec443b- Tree
a7881e8- Author
Junegunn Choi <junegunn.c@gmail.com>- Committer
Junegunn Choi <junegunn.c@gmail.com>- Parent
9e28565
6 files changed+303 added−19 removed
modified:man/man1/fzf.1+34 added
2147 unmodified lines2148 \fBunbind(...)\fR (unbind bindings)2149 \fBunix\-line\-discard\fR \fIctrl\-u\fR2150 \fBunix\-word\-rubout\fR \fIctrl\-w\fR2151 \fBuntrack\-current\fR (stop tracking the current item; no-op if global tracking is enabled)2152+ \fBwait\fR (block action execution until search completes)2153 \fBup\fR \fIctrl\-k up\fR2154 \fBup\-match\fR \fIctrl\-p\fR \fIalt\-up\fR (move to the match above the cursor)2155 \fBup\-selected\fR (move to the selected item above the cursor)2156 \fByank\fR \fIctrl\-y\fR144 unmodified lines2301 chain multiple transform actions where later ones depend on earlier results,2302 prefer using the \fBbg\fR variant. To cancel currently running background2303 transform processes, use \fBbg\-cancel\fR action.2304 2305+.SS WAITING FOR SEARCH COMPLETION2306+2307+The \fBwait\fR action blocks the execution of subsequent actions until the2308+current search completes. This is useful when chaining query\-changing actions2309+with motion actions like \fBbest\fR or \fBfirst\fR, ensuring that the motion2310+action operates on the complete search results rather than stale data.2311+2312+e.g.2313+ \fBfzf \-\-bind 'start:change\-query(foo)+wait+best'\fR2314+2315+In this example, \fBchange\-query(foo)\fR starts an asynchronous search for2316+the new query, \fBwait\fR blocks until the search completes, and \fBbest\fR2317+then moves the cursor to the best match in the complete result set.2318+2319+The initial loading of the input is also considered a search in progress, so2320+\fBstart:wait\fR can be used to block until the input is fully loaded and2321+searched.2322+2323+While waiting, user input is ignored, except for keys bound to \fBabort\fR or2324+\fBcancel\fR (\fIctrl\-c\fR, \fIctrl\-g\fR, \fIctrl\-q\fR, and \fIesc\fR by2325+default), which cancel the wait and discard the pending actions instead of2326+performing their usual role. The remaining actions of such a binding still run,2327+so a binding like \fBesc:cancel+first\fR is possible.2328+2329+If the search takes long enough, fzf indicates that it is waiting by dimming the2330+input, hiding the cursor, and showing \fB(..)\fR on the info line. This visual2331+feedback is debounced so that quick searches do not cause flickering.2332+2333+Note that when searches are triggered in rapid succession (e.g. via2334+\fB\-\-listen\fR), \fBwait\fR may unblock on the completion of an earlier2335+search. Also, if the input source never completes, \fBwait\fR will block until2336+cancelled.2337+2338 .SS PREVIEW BINDING2339 2340 With \fBpreview(...)\fR action, you can specify multiple different preview2341 commands in addition to the default preview command given by \fB\-\-preview\fR47 unmodified linesmodified:src/actiontype_string.go+3 added-2 removed
184 unmodified lines185 _ = x[actBell-174]186 _ = x[actExclude-175]187 _ = x[actExcludeMulti-176]188 _ = x[actAsync-177]189+ _ = x[actWait-178]190 }191 191-const _actionType_name = "actIgnoreactStartactClickactInvalidactBracketedPasteBeginactBracketedPasteEndactCharactMouseactBeginningOfLineactAbortactAcceptactAcceptNonEmptyactAcceptOrPrintQueryactBackwardCharactBackwardDeleteCharactBackwardDeleteCharEofactBackwardWordactBackwardSubWordactCancelactChangeBorderLabelactChangeGhostactChangeHeaderactChangeHeaderLinesactChangeFooteractChangeHeaderLabelactChangeFooterLabelactChangeInputLabelactChangeListLabelactChangeMultiactChangeNthactChangeWithNthactChangePointeractChangePreviewactChangePreviewLabelactChangePreviewWindowactChangePromptactChangeQueryactClearScreenactClearQueryactClearSelectionactCloseactDeleteCharactDeleteCharEofactEndOfLineactFatalactForwardCharactForwardWordactForwardSubWordactKillLineactKillWordactKillSubWordactUnixLineDiscardactUnixWordRuboutactYankactBackwardKillWordactBackwardKillSubWordactSelectAllactDeselectAllactToggleactToggleSearchactToggleAllactToggleDownactToggleUpactToggleInactToggleOutactToggleTrackactToggleTrackCurrentactToggleHeaderactToggleWrapactToggleWrapWordactToggleMultiLineactToggleHscrollactToggleRawactEnableRawactDisableRawactTrackCurrentactToggleInputactHideInputactShowInputactUntrackCurrentactDownactDownMatchactUpactUpMatchactPageUpactPageDownactPositionactHalfPageUpactHalfPageDownactOffsetUpactOffsetDownactOffsetMiddleactJumpactJumpAcceptactPrintQueryactRefreshPreviewactReplaceQueryactToggleSortactShowPreviewactHidePreviewactTogglePreviewactTogglePreviewWrapactTogglePreviewWrapWordactTransformactTransformBorderLabelactTransformGhostactTransformHeaderactTransformHeaderLinesactTransformFooteractTransformHeaderLabelactTransformFooterLabelactTransformInputLabelactTransformListLabelactTransformNthactTransformWithNthactTransformPointeractTransformPreviewLabelactTransformPromptactTransformQueryactTransformSearchactTriggeractBgTransformactBgTransformBorderLabelactBgTransformGhostactBgTransformHeaderactBgTransformHeaderLinesactBgTransformFooteractBgTransformHeaderLabelactBgTransformFooterLabelactBgTransformInputLabelactBgTransformListLabelactBgTransformNthactBgTransformWithNthactBgTransformPointeractBgTransformPreviewLabelactBgTransformPromptactBgTransformQueryactBgTransformSearchactBgCancelactSearchactPreviewactPreviewTopactPreviewBottomactPreviewUpactPreviewDownactPreviewPageUpactPreviewPageDownactPreviewHalfPageUpactPreviewHalfPageDownactPrevHistoryactPrevSelectedactPrintactPutactNextHistoryactNextSelectedactExecuteactExecuteSilentactExecuteMultiactSigStopactBestactFirstactLastactReloadactReloadSyncactDisableSearchactEnableSearchactSelectactDeselectactUnbindactRebindactToggleBindactBecomeactShowHeaderactHideHeaderactBellactExcludeactExcludeMultiactAsync"192+const _actionType_name = "actIgnoreactStartactClickactInvalidactBracketedPasteBeginactBracketedPasteEndactCharactMouseactBeginningOfLineactAbortactAcceptactAcceptNonEmptyactAcceptOrPrintQueryactBackwardCharactBackwardDeleteCharactBackwardDeleteCharEofactBackwardWordactBackwardSubWordactCancelactChangeBorderLabelactChangeGhostactChangeHeaderactChangeHeaderLinesactChangeFooteractChangeHeaderLabelactChangeFooterLabelactChangeInputLabelactChangeListLabelactChangeMultiactChangeNthactChangeWithNthactChangePointeractChangePreviewactChangePreviewLabelactChangePreviewWindowactChangePromptactChangeQueryactClearScreenactClearQueryactClearSelectionactCloseactDeleteCharactDeleteCharEofactEndOfLineactFatalactForwardCharactForwardWordactForwardSubWordactKillLineactKillWordactKillSubWordactUnixLineDiscardactUnixWordRuboutactYankactBackwardKillWordactBackwardKillSubWordactSelectAllactDeselectAllactToggleactToggleSearchactToggleAllactToggleDownactToggleUpactToggleInactToggleOutactToggleTrackactToggleTrackCurrentactToggleHeaderactToggleWrapactToggleWrapWordactToggleMultiLineactToggleHscrollactToggleRawactEnableRawactDisableRawactTrackCurrentactToggleInputactHideInputactShowInputactUntrackCurrentactDownactDownMatchactUpactUpMatchactPageUpactPageDownactPositionactHalfPageUpactHalfPageDownactOffsetUpactOffsetDownactOffsetMiddleactJumpactJumpAcceptactPrintQueryactRefreshPreviewactReplaceQueryactToggleSortactShowPreviewactHidePreviewactTogglePreviewactTogglePreviewWrapactTogglePreviewWrapWordactTransformactTransformBorderLabelactTransformGhostactTransformHeaderactTransformHeaderLinesactTransformFooteractTransformHeaderLabelactTransformFooterLabelactTransformInputLabelactTransformListLabelactTransformNthactTransformWithNthactTransformPointeractTransformPreviewLabelactTransformPromptactTransformQueryactTransformSearchactTriggeractBgTransformactBgTransformBorderLabelactBgTransformGhostactBgTransformHeaderactBgTransformHeaderLinesactBgTransformFooteractBgTransformHeaderLabelactBgTransformFooterLabelactBgTransformInputLabelactBgTransformListLabelactBgTransformNthactBgTransformWithNthactBgTransformPointeractBgTransformPreviewLabelactBgTransformPromptactBgTransformQueryactBgTransformSearchactBgCancelactSearchactPreviewactPreviewTopactPreviewBottomactPreviewUpactPreviewDownactPreviewPageUpactPreviewPageDownactPreviewHalfPageUpactPreviewHalfPageDownactPrevHistoryactPrevSelectedactPrintactPutactNextHistoryactNextSelectedactExecuteactExecuteSilentactExecuteMultiactSigStopactBestactFirstactLastactReloadactReloadSyncactDisableSearchactEnableSearchactSelectactDeselectactUnbindactRebindactToggleBindactBecomeactShowHeaderactHideHeaderactBellactExcludeactExcludeMultiactAsyncactWait"193 193-var _actionType_index = [...]uint16{0, 9, 17, 25, 35, 57, 77, 84, 92, 110, 118, 127, 144, 165, 180, 201, 225, 240, 258, 267, 287, 301, 316, 336, 351, 371, 391, 410, 428, 442, 454, 470, 486, 502, 523, 545, 560, 574, 588, 601, 618, 626, 639, 655, 667, 675, 689, 703, 720, 731, 742, 756, 774, 791, 798, 817, 839, 851, 865, 874, 889, 901, 914, 925, 936, 948, 962, 983, 998, 1011, 1028, 1046, 1062, 1074, 1086, 1099, 1114, 1128, 1140, 1152, 1169, 1176, 1188, 1193, 1203, 1212, 1223, 1234, 1247, 1262, 1273, 1286, 1301, 1308, 1321, 1334, 1351, 1366, 1379, 1393, 1407, 1423, 1443, 1467, 1479, 1502, 1519, 1537, 1560, 1578, 1601, 1624, 1646, 1667, 1682, 1701, 1720, 1744, 1762, 1779, 1797, 1807, 1821, 1846, 1865, 1885, 1910, 1930, 1955, 1980, 2004, 2027, 2044, 2065, 2086, 2112, 2132, 2151, 2171, 2182, 2191, 2201, 2214, 2230, 2242, 2256, 2272, 2290, 2310, 2332, 2346, 2361, 2369, 2375, 2389, 2404, 2414, 2430, 2445, 2455, 2462, 2470, 2477, 2486, 2499, 2515, 2530, 2539, 2550, 2559, 2568, 2581, 2590, 2603, 2616, 2623, 2633, 2648, 2656}194+var _actionType_index = [...]uint16{0, 9, 17, 25, 35, 57, 77, 84, 92, 110, 118, 127, 144, 165, 180, 201, 225, 240, 258, 267, 287, 301, 316, 336, 351, 371, 391, 410, 428, 442, 454, 470, 486, 502, 523, 545, 560, 574, 588, 601, 618, 626, 639, 655, 667, 675, 689, 703, 720, 731, 742, 756, 774, 791, 798, 817, 839, 851, 865, 874, 889, 901, 914, 925, 936, 948, 962, 983, 998, 1011, 1028, 1046, 1062, 1074, 1086, 1099, 1114, 1128, 1140, 1152, 1169, 1176, 1188, 1193, 1203, 1212, 1223, 1234, 1247, 1262, 1273, 1286, 1301, 1308, 1321, 1334, 1351, 1366, 1379, 1393, 1407, 1423, 1443, 1467, 1479, 1502, 1519, 1537, 1560, 1578, 1601, 1624, 1646, 1667, 1682, 1701, 1720, 1744, 1762, 1779, 1797, 1807, 1821, 1846, 1865, 1885, 1910, 1930, 1955, 1980, 2004, 2027, 2044, 2065, 2086, 2112, 2132, 2151, 2171, 2182, 2191, 2201, 2214, 2230, 2242, 2256, 2272, 2290, 2310, 2332, 2346, 2361, 2369, 2375, 2389, 2404, 2414, 2430, 2445, 2455, 2462, 2470, 2477, 2486, 2499, 2515, 2530, 2539, 2550, 2559, 2568, 2581, 2590, 2603, 2616, 2623, 2633, 2648, 2656, 2663}195 196 func (i actionType) String() string {197 if i < 0 || i >= actionType(len(_actionType_index)-1) {198 return "actionType(" + strconv.FormatInt(int64(i), 10) + ")"3 unmodified linesmodified:src/options.go+2 added
1956 unmodified lines1957 appendAction(actChar)1958 } else {1959 return nil, errors.New("unable to put non-printable character")1960 }1961+ case "wait":1962+ appendAction(actWait)1963 case "bell":1964 appendAction(actBell)1965 case "exclude":1966 appendAction(actExclude)2028 unmodified linesmodified:src/terminal.go+176 added-17 removed
142 unmodified lines143 code int144 err error145 }146 147+type waitState struct {148+ blocked bool149+ blockedAt time.Time150+ pending []*action151+ searching bool // a search is in progress or the input is still loading152+}153+154 type previewer struct {155 version int64156 lines []string157 offset int173 unmodified lines331 trackKey string332 trackBlocked bool333 trackSync bool334 trackKeyCache map[int32]bool335+ wait waitState336 pendingSelections map[string]selectedItem337 targetIndex int32338 delimiter Delimiter339 expect map[tui.Event]string391 unmodified lines731 actBell732 actExclude733 actExcludeMulti734 actAsync735+ actWait736 )737 738 func (a actionType) Name() string {739 return util.ToKebabCase(a.String()[3:])436 unmodified lines1176 executing: util.NewAtomicBool(false),1177 lastAction: actStart,1178 lastFocus: minItem.Index(),1179 lastActivity: time.Now(),1171- numLinesCache: make(map[int32]numLinesCacheValue)}1180+ numLinesCache: make(map[int32]numLinesCacheValue),1181+ // The initial load counts as a search in progress ('start:wait').1182+ // Set before the reader starts so the first final result clears it.1183+ wait: waitState{searching: true}}1184 if opts.AcceptNth != nil {1185 t.acceptNth = opts.AcceptNth(t.delimiter)1186 }1187 705 unmodified lines1893 // UpdateList updates Merger to display the list1894 func (t *Terminal) UpdateList(result MatchResult) {1895 merger := result.merger1896 t.mutex.Lock()1897+ waitWasBlocked := t.wait.blocked1898+ wakeUp := false1899+ if result.final() {1900+ t.wait.searching = false1901+ // If waiting, unblock so main loop can execute pending actions.1902+ // Note: any final result unblocks the wait, not just the one for the1903+ // search that armed it. Back-to-back searches (--listen, reload+wait)1904+ // can therefore unblock early and run the pending actions on the1905+ // previous result set. Accepted; a per-search generation token1906+ // through the matcher isn't worth the complexity.1907+ if t.wait.blocked {1908+ t.unblockWait()1909+ wakeUp = len(t.wait.pending) > 01910+ }1911+ }1912 prevIndex := minItem.Index()1913 newRevision := merger.Revision()1914 if t.revision.compatible(newRevision) && t.track != trackDisabled {1915 if t.merger.Length() > 0 {157 unmodified lines2073 }2074 }2075 }2076 updateList := !t.trackBlocked && !t.pendingReqList2050- updatePrompt := trackWasBlocked && !t.trackBlocked2077+ updatePrompt := (trackWasBlocked && !t.trackBlocked) || (waitWasBlocked && !t.wait.blocked)2078 t.mutex.Unlock()2079 2080+ // Wake up the main loop to execute pending actions after wait unblocks.2081+ // Send from a goroutine; UpdateList runs inside the event box callback,2082+ // and an inline send on a full channel would deadlock with the main loop2083+ // blocking on eventBox.Set while trying to drain the channel.2084+ if wakeUp {2085+ go func() {2086+ t.serverInputChan <- []*action{{t: actIgnore}}2087+ }()2088+ }2089+2090 t.reqBox.Set(reqInfo, nil)2091 if updateList {2092 t.reqBox.Set(reqList, nil)2093 }1207 unmodified lines3301 3302 color := tui.ColInput3303 if t.paused {3304 color = tui.ColDisabled3268- } else if t.trackBlocked {3305+ } else if t.trackBlocked || t.waitFeedback() {3306 color = color.WithAttr(tui.Dim)3307 }3308 w.CPrint(color, string(before))3309 w.CPrint(color, string(after))83 unmodified lines3393 } else {3394 output += fmt.Sprintf(" (%d/%d)", len(t.selected), t.multi)3395 }3396 }3360- if t.progress > 0 && t.progress < 100 {3361- output += fmt.Sprintf(" (%d%%)", t.progress)3362- }3397 if t.toggleSort {3398 if t.sort {3399 output += " +S"3400 } else {12 unmodified lines3413 } else {3414 output += " +t"3415 }3416 }3417+ if t.waitFeedback() {3418+ output += " (..)"3419+ }3420+ // Keep the search progress at the end so the other indicators don't shift3421+ // as it appears and disappears.3422+ if t.progress > 0 && t.progress < 100 {3423+ output += fmt.Sprintf(" (%d%%)", t.progress)3424+ }3425 if t.failed != nil && t.count == 0 {3426 output = fmt.Sprintf("[Command failed: %s]", *t.failed)3427 }3428 var outputPrinter labelPrinter2398 unmodified lines5827 if t.trackBlocked {5828 t.trackBlocked = false5829 t.trackKey = ""5830 t.trackKeyCache = nil5789- if !t.inputless {5831+ // Keep the cursor hidden if the wait feedback is still showing it5832+ if !t.inputless && !t.waitFeedback() {5833 t.tui.ShowCursor()5834 }5835 }5836 }5837 5838+// The wait state machine. Invariant: arming captures every action after5839+// 'wait' at any nesting level into wait.pending; while blocked, actions5840+// are dropped; abort/cancel discards everything.5841+5842+// blockWait blocks action execution and defers the given actions until the5843+// current search completes (see UpdateList)5844+func (t *Terminal) blockWait(pending []*action) {5845+ t.wait.blocked = true5846+ t.wait.blockedAt = time.Now()5847+ // Clone so that later joins don't append into the backing array of the5848+ // bound action list5849+ t.wait.pending = slices.Clone(pending)5850+ // Show the waiting feedback only if the search takes long enough,5851+ // so that quick searches don't cause flickering5852+ go func() {5853+ timer := time.NewTimer(progressMinDuration)5854+ <-timer.C5855+ t.mutex.Lock()5856+ blocked := t.wait.blocked5857+ t.mutex.Unlock()5858+ if blocked {5859+ t.reqBox.Set(reqPrompt, nil)5860+ t.reqBox.Set(reqInfo, nil)5861+ }5862+ }()5863+}5864+5865+// unblockWait lifts the block, leaving the pending actions to the caller:5866+// UpdateList keeps them for the main loop to replay, cancelWait discards them5867+func (t *Terminal) unblockWait() {5868+ t.wait.blocked = false5869+ // Restore the cursor unless it's still hidden for another reason5870+ if !t.inputless && !t.trackBlocked {5871+ t.tui.ShowCursor()5872+ }5873+}5874+5875+// cancelWait unblocks and discards the pending actions (user abort)5876+func (t *Terminal) cancelWait() {5877+ t.unblockWait()5878+ t.wait.pending = nil5879+}5880+5881+// Debounce visual feedback so quick searches don't cause flashing5882+func (t *Terminal) waitFeedback() bool {5883+ return t.wait.blocked && time.Since(t.wait.blockedAt) > progressMinDuration5884+}5885+5886 func (t *Terminal) addClickHeaderWord(env []string) []string {5887 /*5888 * echo $'HL1\nHL2' | fzf --header-lines 3 --header $'H1\nH2' --header-lines-border --bind 'click-header:preview:env | grep FZF_CLICK'5889 *617 unmodified lines6507 if footer {6508 t.printFooter()6509 }6510 }6511+ // Hide the cursor while the debounced waiting feedback is shown6512+ if !t.inputless && !t.trackBlocked && t.waitFeedback() {6513+ t.tui.HideCursor()6514+ }6515 t.flush()6516 t.mutex.Unlock()6517 t.uiMutex.Unlock()6518 })139 unmodified lines6658 }6659 }6660 6661 t.mutex.Lock()6662+ // Ignore --expect keys while wait-blocked like the rest of the input6663+ if !t.wait.blocked {6567- for key, ret := range t.expect {6568- if keyMatch(key, event) {6569- t.pressed = ret6570- t.mutex.Unlock()6571- t.reqBox.Set(reqClose, nil)6572- return nil6664+ for key, ret := range t.expect {6665+ if keyMatch(key, event) {6666+ t.pressed = ret6667+ t.mutex.Unlock()6668+ t.reqBox.Set(reqClose, nil)6669+ return nil6670+ }6671 }6672 }6673 triggering := map[tui.Event]struct{}{}6674 previousInput := t.input41 unmodified lines6716 }6717 6718 var doAction func(*action) bool6719 doActions := func(actions []*action) bool {6720+ // Snapshot to detect query edits in this batch that trigger a6721+ // search at loop end without setting 'changed'. String copy:6722+ // edits mutate t.input in place.6723+ queryBefore := string(t.input)6724 for iter := 0; iter <= maxFocusEvents; iter++ {6725 currentIndex := t.currentIndex()6624- for _, action := range actions {6726+ for i, action := range actions {6727+ if action.t == actWait {6728+ // Already waiting; ignore so input can't reset the blocked state6729+ if t.wait.blocked {6730+ return true6731+ }6732+ // Block if search is in progress or will be triggered6733+ if changed || newCommand != nil || t.wait.searching || queryBefore != string(t.input) {6734+ t.blockWait(actions[i+1:])6735+ return true6736+ }6737+ // No search, wait is a no-op; continue to next action6738+ continue6739+ }6740+ blockedBefore := t.wait.blocked6741 if !doAction(action) {6742 return false6743 }6744+ // If this action armed the wait through a nested list6745+ // (e.g. via trigger), defer the rest of this list too6746+ if !blockedBefore && t.wait.blocked {6747+ t.wait.pending = append(t.wait.pending, actions[i+1:]...)6748+ return true6749+ }6750 // A terminal action performed. We should stop processing more.6751 if !looping {6752 break6753 }37 unmodified lines6791 // change-*6792 callback(a.a)6793 }6794 }6795+ // When wait-blocked, only allow abort/cancel6796+ if t.wait.blocked {6797+ if a.t == actAbort || a.t == actCancel {6798+ t.cancelWait()6799+ req(reqPrompt, reqInfo)6800+ }6801+ return true6802+ }6803 // When track-blocked, only allow abort/cancel and track-disabling actions6804 if t.trackBlocked && a.t != actToggleTrack && a.t != actToggleTrackCurrent && a.t != actUntrackCurrent {6805 if a.t == actAbort || a.t == actCancel {6806 t.unblockTrack()876 unmodified lines7683 t.paused = true7684 req(reqPrompt)7685 case actTrigger:7686 if _, chords, err := parseKeyChords(a.a, ""); err == nil {7687+ blockedBefore := t.wait.blocked7557- for _, chord := range chords {7688+ for ci, chord := range chords {7689 if _, prs := triggering[chord]; prs {7690 // Avoid recursive triggering7691 continue7692 }1 unmodified line7694 triggering[chord] = struct{}{}7695 doActions(acts)7696 delete(triggering, chord)7697 }7698+ // If this chord armed the wait, defer the remaining chords7699+ if !blockedBefore && t.wait.blocked {7700+ for _, rest := range chords[ci+1:] {7701+ if _, prs := triggering[rest]; prs {7702+ // Avoid recursive triggering7703+ continue7704+ }7705+ if acts, prs := t.keymap[rest]; prs {7706+ t.wait.pending = append(t.wait.pending, acts...)7707+ }7708+ }7709+ break7710+ }7711 }7712 }7713 case actSigStop:7714 p, err := os.FindProcess(os.Getpid())505 unmodified lines8220 }8221 return true8222 }8223 8224+ // Execute pending actions if wait just unblocked. Capture the jump8225+ // state first so that a pending 'jump' action isn't cancelled right8226+ // away by the wake-up event below.8227+ jumpingBefore := t.jumping8228+ if len(t.wait.pending) > 0 && !t.wait.blocked {8229+ pending := t.wait.pending8230+ t.wait.pending = nil8231+ if !doActions(pending) {8232+ continue8233+ }8234+ }8235+8080- if t.jumping == jumpDisabled || len(actions) > 0 {8236+ if jumpingBefore == jumpDisabled || len(actions) > 0 {8237 // Break out of jump mode if any action is submitted to the server8082- if t.jumping != jumpDisabled {8238+ if jumpingBefore != jumpDisabled {8239 t.jumping = jumpDisabled8240 if acts, prs := t.keymap[tui.JumpCancel.AsEvent()]; prs && !doActions(acts) {8241 continue8242 }50 unmodified lines8293 req(reqPrompt)8294 }8295 8296 reload := changed || newCommand != nil8297+ if reload {8298+ t.wait.searching = true8299+ }8300 var reloadRequest *searchRequest8301 if reload {8302 reloadRequest = &searchRequest{sort: t.sort, sync: reloadSync, nth: newNth, withNth: newWithNth, headerLines: newHeaderLines, command: newCommand, environ: t.environ(), changed: changed, denylist: denylist, revision: t.resultMerger.Revision()}8303 }243 unmodified linesmodified:test/test_core.rb+77 added
1160 unmodified lines1161 tmux.send_keys :BSpace, '0'1162 tmux.until { |lines| assert_equal 10, lines.match_count }1163 end1164 1165+ def test_wait_action1166+ tmux.send_keys %((seq 100; sleep 15) | #{FZF} --bind 'start:search(1)+wait+best'), :Enter1167+ tmux.until { |lines| assert_equal 20, lines.match_count }1168+ tmux.until { |lines| assert lines.any_include?('20/100 (..)') }1169+ tmux.send_keys 'C-c'1170+ tmux.until { |lines| refute lines.any_include?('20/100 (..)') }1171+ # Ctrl-C cancels the wait; fzf keeps running and accepts input again1172+ tmux.send_keys '99'1173+ tmux.until { |lines| assert_equal 1, lines.match_count }1174+ end1175+1176+ def test_wait_action_start1177+ # 'start:wait' blocks on the initial load until reading completes1178+ tmux.send_keys %((seq 100; sleep 15) | #{FZF} --bind 'start:wait'), :Enter1179+ tmux.until { |lines| assert_equal 100, lines.match_count }1180+ tmux.until { |lines| assert lines.any_include?('(..)') }1181+ tmux.send_keys 'C-c'1182+ tmux.until { |lines| refute lines.any_include?('(..)') }1183+ # Ctrl-C cancels the wait; fzf keeps running and accepts input again1184+ tmux.send_keys '99'1185+ tmux.until { |lines| assert_equal 1, lines.match_count }1186+ end1187+1188+ def test_wait_action_query_change1189+ # Query-editing actions must also make wait block; accept must run on the1190+ # results of the new query, not the stale ones1191+ tmux.send_keys %(seq 100 | #{fzf("--bind 'space:change-query(55)+wait+accept'")}), :Enter1192+ tmux.until { |lines| assert_equal 100, lines.match_count }1193+ tmux.send_keys :Space1194+ assert_equal '55', fzf_output1195+ end1196+1197+ def test_wait_action_trigger_join1198+ # A wait armed inside a triggered chord defers the remaining actions of1199+ # the outer binding as well1200+ tmux.send_keys %((seq 100; sleep 2) | #{FZF} --bind 'start:trigger(x)+change-footer(world)' --bind 'x:search(5)+wait'), :Enter1201+ tmux.until { |lines| assert(lines.any_include?('(..)') && !lines.any_include?('world')) }1202+ tmux.until { |lines| assert(lines.any_include?('world') && !lines.any_include?('(..)')) }1203+ end1204+1205+ def test_wait_action_trigger_siblings1206+ # Chords after a wait-arming chord are deferred, not dropped1207+ tmux.send_keys %((seq 100; sleep 2) | #{FZF} --bind 'start:trigger(x,y)+change-footer(world)' --bind 'x:search(5)+wait' --bind 'y:change-header(hello)'), :Enter1208+ tmux.until { |lines| assert(lines.any_include?('(..)') && !lines.any_include?('hello') && !lines.any_include?('world')) }1209+ tmux.until { |lines| assert(lines.any_include?('hello') && lines.any_include?('world') && !lines.any_include?('(..)')) }1210+ end1211+1212+ def test_wait_action_cancel_rearm1213+ # Deferral works even when the wait is cancelled and re-armed within a1214+ # single action list. --query keeps 'cancel' non-fatal in case the Space1215+ # arrives after the initial wait has already unblocked.1216+ tmux.send_keys %((seq 100; sleep 2) | #{FZF} --query 5 --bind 'start:wait' --bind 'space:cancel+trigger(x)+change-footer(world)' --bind 'x:search(5)+wait'), :Enter1217+ tmux.until { |lines| assert lines.any_include?('(..)') }1218+ tmux.send_keys :Space1219+ tmux.until { |lines| assert(lines.any_include?('world') && !lines.any_include?('(..)')) }1220+ end1221+1222+ def test_wait_action_jump1223+ # A pending jump action must survive the wake-up event after unblock1224+ tmux.send_keys %((seq 100; sleep 2) | #{FZF} --jump-labels abc --bind 'start:search(5)+wait+jump'), :Enter1225+ tmux.until { |lines| assert_equal 'a 5', lines[-3] }1226+ tmux.send_keys 'a'1227+ tmux.until { |lines| assert_equal '> 5', lines[-3] }1228+ end1229+1230+ def test_wait_action_expect1231+ # --expect keys are ignored while wait-blocked, like the rest of the input1232+ tmux.send_keys %((seq 100; sleep 2) | #{fzf('--expect ctrl-t --bind start:wait')}), :Enter1233+ tmux.until { |lines| assert lines.any_include?('(..)') }1234+ tmux.send_keys 'C-t'1235+ # fzf must still be running; the wait unblocks when loading completes1236+ tmux.until { |lines| assert_equal 100, lines.match_count }1237+ tmux.until { |lines| refute lines.any_include?('(..)') }1238+ tmux.send_keys 'C-t'1239+ assert_equal %w[ctrl-t 1], fzf_output_lines1240+ end1241+1242 def test_clear_selection1243 tmux.send_keys %(seq 100 | #{FZF} --multi --bind space:clear-selection), :Enter1244 tmux.until { |lines| assert_equal 100, lines.match_count }1245 tmux.send_keys :Tab1665 unmodified linesmodified:CHANGELOG.md+11 added
9 unmodified lines10 # 'result-final' fires once after the stream closes (footer shows the final count)11 (seq 100; sleep 1; seq 100) | fzf --query 1 \12 --bind 'result:transform-header(echo result: $FZF_MATCH_COUNT),result-final:transform-footer(echo final: $FZF_MATCH_COUNT)'13 ```14+- Added `wait` action to block subsequent actions until search completes (#4825)15+ - Useful for chaining query-changing actions with motion actions to ensure operations on complete results16+ ```sh17+ # Wait for search to complete before moving to the best match18+ fzf --bind 'start:change-query(foo)+wait+best'19+ ```20+ - The initial loading of the input is also considered a search in progress, so `start:wait` can be used to wait until the input is fully loaded21+ ```sh22+ # Move to the last item after the input is fully loaded23+ (seq 1000; sleep 1; seq 1001 2000) | fzf --bind 'start:wait+last'24+ ```25 - Bound `alt-left` to `backward-word` and `alt-right` to `forward-word` by default (#4833)26 - Skip `$FZF_CURRENT_ITEM` export when the item is larger than 64 KB; a huge item can overflow `ARG_MAX` and break preview and other child commands with `E2BIG` (#4806)27 28 0.73.13317 unmodified lines