{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
Provenance
- Commit
97ccef1- Tree
e8a4fe1- Author
Junegunn Choi <junegunn.c@gmail.com>- Committer
Junegunn Choi <junegunn.c@gmail.com>- Parent
c4df0dd
2 files changed+14 added−12 removed
modified:src/terminal_test.go+1 added-1 removed
608 unmodified lines609 }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 linesmodified:src/terminal.go+13 added-11 removed
469 unmodified lines470 type placeholderFlags struct {471 plus bool472 preserveSpace bool473 number bool474- query bool474+ forceUpdate bool475 file bool476 }477 478 type searchRequest struct {1874 unmodified lines2353 return true, match[1:], flags2354 }2355 2356 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 }2361 2362 skipChars := 111 unmodified lines2374 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 lines2386 2387 return false, matchWithoutFlags, flags2388 }2389 2388-func hasPreviewFlags(template string) (slot bool, plus bool, query bool) {2390+func 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 return239 unmodified lines2641 }2642 2643 func (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 }2649 2650 // We would still want to update preview window even if there is no match if1190 unmodified lines3841 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 = &command119 unmodified lines3970 req(reqList)3971 }3972 3973 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