mirror of
https://github.com/Llewellynvdm/fzf.git
synced 2025-02-02 12:08:34 +00:00
Fix search not triggered when query change and reload happen at the same time
Fix #3268
This commit is contained in:
parent
5c2f85c39e
commit
77f9f4664a
11
src/core.go
11
src/core.go
@ -299,10 +299,12 @@ func Run(opts *Options, version string, revision string) {
|
|||||||
|
|
||||||
case EvtSearchNew:
|
case EvtSearchNew:
|
||||||
var command *string
|
var command *string
|
||||||
|
var changed bool
|
||||||
switch val := value.(type) {
|
switch val := value.(type) {
|
||||||
case searchRequest:
|
case searchRequest:
|
||||||
sort = val.sort
|
sort = val.sort
|
||||||
command = val.command
|
command = val.command
|
||||||
|
changed = val.changed
|
||||||
if command != nil {
|
if command != nil {
|
||||||
useSnapshot = val.sync
|
useSnapshot = val.sync
|
||||||
}
|
}
|
||||||
@ -314,10 +316,17 @@ func Run(opts *Options, version string, revision string) {
|
|||||||
} else {
|
} else {
|
||||||
restart(*command)
|
restart(*command)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
if !changed {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
if !useSnapshot {
|
if !useSnapshot {
|
||||||
snapshot, _ = chunkList.Snapshot()
|
newSnapshot, _ := chunkList.Snapshot()
|
||||||
|
// We want to avoid showing empty list when reload is triggered
|
||||||
|
// and the query string is changed at the same time i.e. command != nil && changed
|
||||||
|
if command == nil || len(newSnapshot) > 0 {
|
||||||
|
snapshot = newSnapshot
|
||||||
|
}
|
||||||
}
|
}
|
||||||
reset := !useSnapshot && clearCache()
|
reset := !useSnapshot && clearCache()
|
||||||
matcher.Reset(snapshot, input(reset), true, !reading, sort, reset)
|
matcher.Reset(snapshot, input(reset), true, !reading, sort, reset)
|
||||||
|
@ -408,6 +408,7 @@ type searchRequest struct {
|
|||||||
sort bool
|
sort bool
|
||||||
sync bool
|
sync bool
|
||||||
command *string
|
command *string
|
||||||
|
changed bool
|
||||||
}
|
}
|
||||||
|
|
||||||
type previewRequest struct {
|
type previewRequest struct {
|
||||||
@ -3622,7 +3623,7 @@ func (t *Terminal) Loop() {
|
|||||||
t.mutex.Unlock() // Must be unlocked before touching reqBox
|
t.mutex.Unlock() // Must be unlocked before touching reqBox
|
||||||
|
|
||||||
if changed || newCommand != nil {
|
if changed || newCommand != nil {
|
||||||
t.eventBox.Set(EvtSearchNew, searchRequest{sort: t.sort, sync: reloadSync, command: newCommand})
|
t.eventBox.Set(EvtSearchNew, searchRequest{sort: t.sort, sync: reloadSync, command: newCommand, changed: changed})
|
||||||
}
|
}
|
||||||
for _, event := range events {
|
for _, event := range events {
|
||||||
t.reqBox.Set(event, nil)
|
t.reqBox.Set(event, nil)
|
||||||
|
@ -2861,6 +2861,11 @@ class TestGoFZF < TestBase
|
|||||||
tmux.send_keys :c
|
tmux.send_keys :c
|
||||||
tmux.until { |lines| assert_equal 0, lines.match_count }
|
tmux.until { |lines| assert_equal 0, lines.match_count }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_reload_and_change
|
||||||
|
tmux.send_keys "(echo foo; echo bar) | #{FZF} --bind 'load:reload-sync(sleep 60)+change-query(bar)'", :Enter
|
||||||
|
tmux.until { |lines| assert_equal 1, lines.match_count }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
module TestShell
|
module TestShell
|
||||||
|
Loading…
x
Reference in New Issue
Block a user