mirror of
https://github.com/junegunn/fzf.git
synced 2025-05-19 04:40:22 -07:00
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
This commit is contained in:
parent
f43e82f17f
commit
4a0ab6c926
@ -4934,6 +4934,14 @@ func (t *Terminal) Loop() error {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
doAction = func(a *action) bool {
|
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:
|
Action:
|
||||||
switch a.t {
|
switch a.t {
|
||||||
case actIgnore, actStart, actClick:
|
case actIgnore, actStart, actClick:
|
||||||
@ -6025,6 +6033,13 @@ func (t *Terminal) Loop() error {
|
|||||||
if !processExecution(a.t) {
|
if !processExecution(a.t) {
|
||||||
t.lastAction = 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
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -6045,12 +6060,7 @@ func (t *Terminal) Loop() error {
|
|||||||
} else if !doActions(actions) {
|
} else if !doActions(actions) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if t.inputless {
|
if !t.inputless {
|
||||||
// Always just discard the change
|
|
||||||
t.input = previousInput
|
|
||||||
t.cx = len(t.input)
|
|
||||||
beof = false
|
|
||||||
} else {
|
|
||||||
t.truncateQuery()
|
t.truncateQuery()
|
||||||
}
|
}
|
||||||
queryChanged = queryChanged || t.pasting == nil && string(previousInput) != string(t.input)
|
queryChanged = queryChanged || t.pasting == nil && string(previousInput) != string(t.input)
|
||||||
|
@ -1866,4 +1866,19 @@ class TestCore < TestInteractive
|
|||||||
assert_includes lines, '> 555'
|
assert_includes lines, '> 555'
|
||||||
end
|
end
|
||||||
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
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user