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) diff --git a/test/test_core.rb b/test/test_core.rb index ade644a2..d37a4b47 100644 --- a/test/test_core.rb +++ b/test/test_core.rb @@ -1866,4 +1866,19 @@ class TestCore < TestInteractive assert_includes lines, '> 555' end end + + def test_no_input_change_query + tmux.send_keys %(seq 1000 | #{FZF} --multi --query 999 --no-input --bind 'enter:show-input+change-query(555)+hide-input,space:change-query(555)+select'), :Enter + tmux.until { |lines| assert_includes lines, '> 999' } + tmux.send_keys :Space + tmux.until do |lines| + assert_includes lines, '>>999' + refute_includes lines, '> 555' + end + tmux.send_keys :Enter + tmux.until do |lines| + refute_includes lines, '>>999' + assert_includes lines, '> 555' + end + end end