Skip to content
Myr

{fzf:query} should trigger preview update

Before adoption: this commit came in with the history the project adopted, so no landing records it.

fzf --preview 'echo {fzf:query}' fzf --preview 'echo {q}'

authored by Junegunn Choi · committed by Junegunn Choi · parent c4df0dd · Browse files · 2 files+14 added−12 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+14 added−12 removed

  • other:+14 added−12 removed

2 files+14 added−12 removed

modified:src/terminal_test.go+1 added-1 removed
608 unmodified lines
609 }610 if flags.file {611 encoded += "f"612 }613 if flags.query {613 if flags.forceUpdate { // FIXME614 encoded += "q"615 }616 return encoded617}
26 unmodified lines
modified:src/terminal.go+13 added-11 removed
469 unmodified lines
470type placeholderFlags struct {471 plus bool472 preserveSpace bool473 number bool474 query bool474 forceUpdate bool475 file bool476}477478type searchRequest struct {
1874 unmodified lines
2353 return true, match[1:], flags2354 }23552356 if strings.HasPrefix(match, "{fzf:") {2357 // Both {fzf:query} and {fzf:action} are not determined by the current item2358 flags.forceUpdate = true2359 return false, match, flags2360 }23612362 skipChars := 1
11 unmodified lines
2374 case 'f':2375 flags.file = true2376 skipChars++2377 case 'q':2376 flags.query = true2378 flags.forceUpdate = true2379 // query flag is not skipped2380 default:2381 break2382 }
3 unmodified lines
23862387 return false, matchWithoutFlags, flags2388}23892388func hasPreviewFlags(template string) (slot bool, plus bool, query bool) {2390func hasPreviewFlags(template string) (slot bool, plus bool, forceUpdate bool) {2391 for _, match := range placeholder.FindAllString(template, -1) {2392 _, _, flags := parsePlaceholder(match)2393 if flags.plus {2394 plus = true2395 }2394 if flags.query {2395 query = true2396 if flags.forceUpdate {2397 forceUpdate = true2398 }2399 slot = true2400 }2401 return
239 unmodified lines
2641}26422643func (t *Terminal) buildPlusList(template string, forcePlus bool) (bool, []*Item) {2644 current := t.currentItem()2643 slot, plus, query := hasPreviewFlags(template)2644 if !(!slot || query || (forcePlus || plus) && len(t.selected) > 0) {2645 slot, plus, forceUpdate := hasPreviewFlags(template)2646 if !(!slot || forceUpdate || (forcePlus || plus) && len(t.selected) > 0) {2647 return current != nil, []*Item{current, current}2648 }26492650 // We would still want to update preview window even if there is no match if
1190 unmodified lines
3841 if !valid {3842 // We run the command even when there's no match3843 // 1. If the template doesn't have any slots3844 // 2. If the template has {q}3843 slot, _, query := hasPreviewFlags(a.a)3844 valid = !slot || query3845 slot, _, forceUpdate := hasPreviewFlags(a.a)3846 valid = !slot || forceUpdate3847 }3848 if valid {3849 command := t.replacePlaceholder(a.a, false, string(t.input), list)3850 newCommand = &command
119 unmodified lines
3970 req(reqList)3971 }39723973 if queryChanged && t.canPreview() && len(t.previewOpts.command) > 0 {3972 _, _, q := hasPreviewFlags(t.previewOpts.command)3973 if q {3974 _, _, forceUpdate := hasPreviewFlags(t.previewOpts.command)3975 if forceUpdate {3976 t.version++3977 }3978 }3979
122 unmodified lines