From 4a0ab6c9267ef9e07723c3c19f9007d7ed3ea9b4 Mon Sep 17 00:00:00 2001 From: Junegunn Choi Date: Wed, 26 Mar 2025 10:34:52 +0900 Subject: 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 --- src/terminal.go | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) (limited to 'src/terminal.go') 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) -- cgit v1.2.3