summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJunegunn Choi <junegunn.c@gmail.com>2023-12-26 16:51:41 +0900
committerJunegunn Choi <junegunn.c@gmail.com>2023-12-26 16:51:41 +0900
commit97ccef1a04ef8a3fcffcc6682765d651b86d0480 (patch)
treee8a4fe1dbe0d184fd4d2b97df22bbfb37723daae
parentc4df0dd06e69c9fad90e88ae7f6fbb5d8426077e (diff)
{fzf:query} should trigger preview update
fzf --preview 'echo {fzf:query}' fzf --preview 'echo {q}'
-rw-r--r--src/terminal.go24
-rw-r--r--src/terminal_test.go2
2 files changed, 14 insertions, 12 deletions
diff --git a/src/terminal.go b/src/terminal.go
index 4a1d3ee4..ad860441 100644
--- a/src/terminal.go
+++ b/src/terminal.go
@@ -471,7 +471,7 @@ type placeholderFlags struct {
plus bool
preserveSpace bool
number bool
- query bool
+ forceUpdate bool
file bool
}
@@ -2354,6 +2354,8 @@ func parsePlaceholder(match string) (bool, string, placeholderFlags) {
}
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
}
@@ -2373,7 +2375,7 @@ func parsePlaceholder(match string) (bool, string, placeholderFlags) {
flags.file = true
skipChars++
case 'q':
- flags.query = true
+ flags.forceUpdate = true
// query flag is not skipped
default:
break
@@ -2385,14 +2387,14 @@ func parsePlaceholder(match string) (bool, string, placeholderFlags) {
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) {
_, _, flags := parsePlaceholder(match)
if flags.plus {
plus = true
}
- if flags.query {
- query = true
+ if flags.forceUpdate {
+ forceUpdate = true
}
slot = true
}
@@ -2640,8 +2642,8 @@ func (t *Terminal) currentItem() *Item {
func (t *Terminal) buildPlusList(template string, forcePlus bool) (bool, []*Item) {
current := t.currentItem()
- slot, plus, query := hasPreviewFlags(template)
- if !(!slot || query || (forcePlus || plus) && len(t.selected) > 0) {
+ slot, plus, forceUpdate := hasPreviewFlags(template)
+ if !(!slot || forceUpdate || (forcePlus || plus) && len(t.selected) > 0) {
return current != nil, []*Item{current, current}
}
@@ -3840,8 +3842,8 @@ func (t *Terminal) Loop() {
// We run the command even when there's no match
// 1. If the template doesn't have any slots
// 2. If the template has {q}
- slot, _, query := hasPreviewFlags(a.a)
- valid = !slot || query
+ slot, _, forceUpdate := hasPreviewFlags(a.a)
+ valid = !slot || forceUpdate
}
if valid {
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 {
- _, _, q := hasPreviewFlags(t.previewOpts.command)
- if q {
+ _, _, forceUpdate := hasPreviewFlags(t.previewOpts.command)
+ if forceUpdate {
t.version++
}
}
diff --git a/src/terminal_test.go b/src/terminal_test.go
index 271c64a3..791bebf4 100644
--- a/src/terminal_test.go
+++ b/src/terminal_test.go
@@ -610,7 +610,7 @@ func (flags placeholderFlags) encodePlaceholder() string {
if flags.file {
encoded += "f"
}
- if flags.query {
+ if flags.forceUpdate { // FIXME
encoded += "q"
}
return encoded