Skip to content
Myr

Improve query modification prevention in input-less mode

Before adoption: this commit came in with the history the project adopted, so no landing records it.

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

authored by Junegunn Choi · committed by Junegunn Choi · parent f43e82f · Browse files · 2 files+31 added−6 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+31 added−6 removed

  • tests:+15 added−0 removed
  • other:+16 added−6 removed

2 files+31 added−6 removed

modified:src/terminal.go+16 added-6 removed
4932 unmodified lines
4933 }4934 return true4935 }4936 doAction = func(a *action) bool {4937 // Keep track of the current query before the action is executed,4938 // so we can restore it when the input section is hidden (--no-input).4939 // * By doing this, we don't have to add a conditional branch to each4940 // query modifying action.4941 // * We restore the query after each action instead of after a set of4942 // actions to allow changing the query even when the input is hidden4943 // e.g. fzf --no-input --bind 'space:show-input+change-query(foo)+hide-input'4944 currentInput := t.input4945 Action:4946 switch a.t {4947 case actIgnore, actStart, actClick:4948 case actBecome:
1083 unmodified lines
60326033 if !processExecution(a.t) {6034 t.lastAction = a.t6035 }60366037 if t.inputless {6038 // Always just discard the change6039 t.input = currentInput6040 t.cx = len(t.input)6041 beof = false6042 }6043 return true6044 }60456046 if t.jumping == jumpDisabled || len(actions) > 0 {
12 unmodified lines
6059 doAction(&action{t: actChar})6060 } else if !doActions(actions) {6061 continue6062 }6048 if t.inputless {6049 // Always just discard the change6050 t.input = previousInput6051 t.cx = len(t.input)6052 beof = false6053 } else {6063 if !t.inputless {6064 t.truncateQuery()6065 }6066 queryChanged = queryChanged || t.pasting == nil && string(previousInput) != string(t.input)6067 if queryChanged {
268 unmodified lines
modified:test/test_core.rb+15 added
1864 unmodified lines
1865 assert_equal 1, lines.match_count1866 assert_includes lines, '> 555'1867 end1868 end18691870 def test_no_input_change_query1871 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'), :Enter1872 tmux.until { |lines| assert_includes lines, '> 999' }1873 tmux.send_keys :Space1874 tmux.until do |lines|1875 assert_includes lines, '>>999'1876 refute_includes lines, '> 555'1877 end1878 tmux.send_keys :Enter1879 tmux.until do |lines|1880 refute_includes lines, '>>999'1881 assert_includes lines, '> 555'1882 end1883 end1884end