summaryrefslogtreecommitdiff
path: root/src/terminal.go
diff options
context:
space:
mode:
authorJunegunn Choi <junegunn.c@gmail.com>2025-03-26 10:34:52 +0900
committerJunegunn Choi <junegunn.c@gmail.com>2025-03-26 10:34:52 +0900
commit4a0ab6c9267ef9e07723c3c19f9007d7ed3ea9b4 (patch)
treed042d84e613599d2c529665fd2e0cdaf99d1416b /src/terminal.go
parentf43e82f17fb107d2093e6226833eb68e532c1810 (diff)
downloadfzf-4a0ab6c9267ef9e07723c3c19f9007d7ed3ea9b4.tar.gz
Improve query modification prevention in input-less mode
fzf would restore the original query in input-less mode after executing a chain of actions. This commit changes the behavior so that the restoration happens after each action to allow something like 'show-input+change-query(...)+hide-input'. Fix #4326
Diffstat (limited to 'src/terminal.go')
-rw-r--r--src/terminal.go22
1 files changed, 16 insertions, 6 deletions
diff --git a/src/terminal.go b/src/terminal.go
index 03af52a0..999bfdc0 100644
--- a/src/terminal.go
+++ b/src/terminal.go
@@ -4934,6 +4934,14 @@ func (t *Terminal) Loop() error {
return true
}
doAction = func(a *action) bool {
+ // Keep track of the current query before the action is executed,
+ // so we can restore it when the input section is hidden (--no-input).
+ // * By doing this, we don't have to add a conditional branch to each
+ // query modifying action.
+ // * We restore the query after each action instead of after a set of
+ // actions to allow changing the query even when the input is hidden
+ // e.g. fzf --no-input --bind 'space:show-input+change-query(foo)+hide-input'
+ currentInput := t.input
Action:
switch a.t {
case actIgnore, actStart, actClick:
@@ -6025,6 +6033,13 @@ func (t *Terminal) Loop() error {
if !processExecution(a.t) {
t.lastAction = a.t
}
+
+ if t.inputless {
+ // Always just discard the change
+ t.input = currentInput
+ t.cx = len(t.input)
+ beof = false
+ }
return true
}
@@ -6045,12 +6060,7 @@ func (t *Terminal) Loop() error {
} else if !doActions(actions) {
continue
}
- if t.inputless {
- // Always just discard the change
- t.input = previousInput
- t.cx = len(t.input)
- beof = false
- } else {
+ if !t.inputless {
t.truncateQuery()
}
queryChanged = queryChanged || t.pasting == nil && string(previousInput) != string(t.input)