mirror of
https://github.com/Llewellynvdm/fzf.git
synced 2024-06-04 00:10:49 +00:00
{fzf:query} should trigger preview update
fzf --preview 'echo {fzf:query}' fzf --preview 'echo {q}'
This commit is contained in:
parent
c4df0dd06e
commit
97ccef1a04
|
@ -471,7 +471,7 @@ type placeholderFlags struct {
|
||||||
plus bool
|
plus bool
|
||||||
preserveSpace bool
|
preserveSpace bool
|
||||||
number bool
|
number bool
|
||||||
query bool
|
forceUpdate bool
|
||||||
file bool
|
file bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2354,6 +2354,8 @@ func parsePlaceholder(match string) (bool, string, placeholderFlags) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if strings.HasPrefix(match, "{fzf:") {
|
if strings.HasPrefix(match, "{fzf:") {
|
||||||
|
// Both {fzf:query} and {fzf:action} are not determined by the current item
|
||||||
|
flags.forceUpdate = true
|
||||||
return false, match, flags
|
return false, match, flags
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2373,7 +2375,7 @@ func parsePlaceholder(match string) (bool, string, placeholderFlags) {
|
||||||
flags.file = true
|
flags.file = true
|
||||||
skipChars++
|
skipChars++
|
||||||
case 'q':
|
case 'q':
|
||||||
flags.query = true
|
flags.forceUpdate = true
|
||||||
// query flag is not skipped
|
// query flag is not skipped
|
||||||
default:
|
default:
|
||||||
break
|
break
|
||||||
|
@ -2385,14 +2387,14 @@ func parsePlaceholder(match string) (bool, string, placeholderFlags) {
|
||||||
return false, matchWithoutFlags, flags
|
return false, matchWithoutFlags, flags
|
||||||
}
|
}
|
||||||
|
|
||||||
func hasPreviewFlags(template string) (slot bool, plus bool, query bool) {
|
func hasPreviewFlags(template string) (slot bool, plus bool, forceUpdate bool) {
|
||||||
for _, match := range placeholder.FindAllString(template, -1) {
|
for _, match := range placeholder.FindAllString(template, -1) {
|
||||||
_, _, flags := parsePlaceholder(match)
|
_, _, flags := parsePlaceholder(match)
|
||||||
if flags.plus {
|
if flags.plus {
|
||||||
plus = true
|
plus = true
|
||||||
}
|
}
|
||||||
if flags.query {
|
if flags.forceUpdate {
|
||||||
query = true
|
forceUpdate = true
|
||||||
}
|
}
|
||||||
slot = true
|
slot = true
|
||||||
}
|
}
|
||||||
|
@ -2640,8 +2642,8 @@ func (t *Terminal) currentItem() *Item {
|
||||||
|
|
||||||
func (t *Terminal) buildPlusList(template string, forcePlus bool) (bool, []*Item) {
|
func (t *Terminal) buildPlusList(template string, forcePlus bool) (bool, []*Item) {
|
||||||
current := t.currentItem()
|
current := t.currentItem()
|
||||||
slot, plus, query := hasPreviewFlags(template)
|
slot, plus, forceUpdate := hasPreviewFlags(template)
|
||||||
if !(!slot || query || (forcePlus || plus) && len(t.selected) > 0) {
|
if !(!slot || forceUpdate || (forcePlus || plus) && len(t.selected) > 0) {
|
||||||
return current != nil, []*Item{current, current}
|
return current != nil, []*Item{current, current}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3840,8 +3842,8 @@ func (t *Terminal) Loop() {
|
||||||
// We run the command even when there's no match
|
// We run the command even when there's no match
|
||||||
// 1. If the template doesn't have any slots
|
// 1. If the template doesn't have any slots
|
||||||
// 2. If the template has {q}
|
// 2. If the template has {q}
|
||||||
slot, _, query := hasPreviewFlags(a.a)
|
slot, _, forceUpdate := hasPreviewFlags(a.a)
|
||||||
valid = !slot || query
|
valid = !slot || forceUpdate
|
||||||
}
|
}
|
||||||
if valid {
|
if valid {
|
||||||
command := t.replacePlaceholder(a.a, false, string(t.input), list)
|
command := t.replacePlaceholder(a.a, false, string(t.input), list)
|
||||||
|
@ -3969,8 +3971,8 @@ func (t *Terminal) Loop() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if queryChanged && t.canPreview() && len(t.previewOpts.command) > 0 {
|
if queryChanged && t.canPreview() && len(t.previewOpts.command) > 0 {
|
||||||
_, _, q := hasPreviewFlags(t.previewOpts.command)
|
_, _, forceUpdate := hasPreviewFlags(t.previewOpts.command)
|
||||||
if q {
|
if forceUpdate {
|
||||||
t.version++
|
t.version++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -610,7 +610,7 @@ func (flags placeholderFlags) encodePlaceholder() string {
|
||||||
if flags.file {
|
if flags.file {
|
||||||
encoded += "f"
|
encoded += "f"
|
||||||
}
|
}
|
||||||
if flags.query {
|
if flags.forceUpdate { // FIXME
|
||||||
encoded += "q"
|
encoded += "q"
|
||||||
}
|
}
|
||||||
return encoded
|
return encoded
|
||||||
|
|
Loading…
Reference in New Issue
Block a user