mirror of
https://github.com/Llewellynvdm/fzf.git
synced 2024-11-10 15:50:56 +00:00
Fix race condition in asynchronous -1 and -0
This commit is contained in:
parent
95e5beb34e
commit
f5b034095a
@ -149,11 +149,11 @@ func Run(options *Options) {
|
|||||||
reading = reading && evt == EvtReadNew
|
reading = reading && evt == EvtReadNew
|
||||||
snapshot, count := chunkList.Snapshot()
|
snapshot, count := chunkList.Snapshot()
|
||||||
terminal.UpdateCount(count, !reading)
|
terminal.UpdateCount(count, !reading)
|
||||||
matcher.Reset(snapshot, terminal.Input(), false)
|
matcher.Reset(snapshot, terminal.Input(), false, !reading)
|
||||||
|
|
||||||
case EvtSearchNew:
|
case EvtSearchNew:
|
||||||
snapshot, _ := chunkList.Snapshot()
|
snapshot, _ := chunkList.Snapshot()
|
||||||
matcher.Reset(snapshot, terminal.Input(), true)
|
matcher.Reset(snapshot, terminal.Input(), true, !reading)
|
||||||
delay = false
|
delay = false
|
||||||
|
|
||||||
case EvtSearchProgress:
|
case EvtSearchProgress:
|
||||||
@ -170,7 +170,7 @@ func Run(options *Options) {
|
|||||||
if opts.Select1 && count > 1 || opts.Exit0 && !opts.Select1 && count > 0 {
|
if opts.Select1 && count > 1 || opts.Exit0 && !opts.Select1 && count > 0 {
|
||||||
deferred = false
|
deferred = false
|
||||||
terminal.startChan <- true
|
terminal.startChan <- true
|
||||||
} else if !reading {
|
} else if val.final {
|
||||||
if opts.Exit0 && count == 0 || opts.Select1 && count == 1 {
|
if opts.Exit0 && count == 0 || opts.Select1 && count == 1 {
|
||||||
if opts.PrintQuery {
|
if opts.PrintQuery {
|
||||||
fmt.Println(opts.Query)
|
fmt.Println(opts.Query)
|
||||||
|
@ -14,6 +14,7 @@ import (
|
|||||||
type MatchRequest struct {
|
type MatchRequest struct {
|
||||||
chunks []*Chunk
|
chunks []*Chunk
|
||||||
pattern *Pattern
|
pattern *Pattern
|
||||||
|
final bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// Matcher is responsible for performing search
|
// Matcher is responsible for performing search
|
||||||
@ -91,6 +92,7 @@ func (m *Matcher) Loop() {
|
|||||||
|
|
||||||
if !cancelled {
|
if !cancelled {
|
||||||
m.mergerCache[patternString] = merger
|
m.mergerCache[patternString] = merger
|
||||||
|
merger.final = request.final
|
||||||
m.eventBox.Set(EvtSearchFin, merger)
|
m.eventBox.Set(EvtSearchFin, merger)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -197,7 +199,7 @@ func (m *Matcher) scan(request MatchRequest) (*Merger, bool) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Reset is called to interrupt/signal the ongoing search
|
// Reset is called to interrupt/signal the ongoing search
|
||||||
func (m *Matcher) Reset(chunks []*Chunk, patternRunes []rune, cancel bool) {
|
func (m *Matcher) Reset(chunks []*Chunk, patternRunes []rune, cancel bool, final bool) {
|
||||||
pattern := m.patternBuilder(patternRunes)
|
pattern := m.patternBuilder(patternRunes)
|
||||||
|
|
||||||
var event util.EventType
|
var event util.EventType
|
||||||
@ -206,5 +208,5 @@ func (m *Matcher) Reset(chunks []*Chunk, patternRunes []rune, cancel bool) {
|
|||||||
} else {
|
} else {
|
||||||
event = reqRetry
|
event = reqRetry
|
||||||
}
|
}
|
||||||
m.reqBox.Set(event, MatchRequest{chunks, pattern})
|
m.reqBox.Set(event, MatchRequest{chunks, pattern, final})
|
||||||
}
|
}
|
||||||
|
@ -12,6 +12,7 @@ type Merger struct {
|
|||||||
merged []*Item
|
merged []*Item
|
||||||
cursors []int
|
cursors []int
|
||||||
sorted bool
|
sorted bool
|
||||||
|
final bool
|
||||||
count int
|
count int
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -22,6 +23,7 @@ func NewMerger(lists [][]*Item, sorted bool) *Merger {
|
|||||||
merged: []*Item{},
|
merged: []*Item{},
|
||||||
cursors: make([]int, len(lists)),
|
cursors: make([]int, len(lists)),
|
||||||
sorted: sorted,
|
sorted: sorted,
|
||||||
|
final: false,
|
||||||
count: 0}
|
count: 0}
|
||||||
|
|
||||||
for _, list := range mg.lists {
|
for _, list := range mg.lists {
|
||||||
|
@ -290,6 +290,16 @@ class TestGoFZF < MiniTest::Unit::TestCase
|
|||||||
assert_equal ['555555'], readonce.split($/)
|
assert_equal ['555555'], readonce.split($/)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_select_1_exit_0_fail
|
||||||
|
[:'0', :'1', [:'1', :'0']].each do |opt|
|
||||||
|
tmux.send_keys "seq 1 100 | #{fzf :print_query, :multi, :q, 5, *opt}", :Enter
|
||||||
|
tmux.until { |lines| lines.last =~ /^> 5/ }
|
||||||
|
tmux.send_keys :BTab, :BTab, :BTab, :Enter
|
||||||
|
tmux.until { |lines| lines[-1].include?(FIN) }
|
||||||
|
assert_equal ['5', '5', '15', '25'], readonce.split($/)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def test_query_unicode
|
def test_query_unicode
|
||||||
tmux.send_keys "(echo abc; echo 가나다) | #{fzf :query, '가다'}", :Enter
|
tmux.send_keys "(echo abc; echo 가나다) | #{fzf :query, '가다'}", :Enter
|
||||||
tmux.until { |lines| lines.last.start_with? '>' }
|
tmux.until { |lines| lines.last.start_with? '>' }
|
||||||
|
Loading…
Reference in New Issue
Block a user