mirror of
https://github.com/Llewellynvdm/fzf.git
synced 2024-11-18 02:55:11 +00:00
Defer resetting multi-selection on reload
This commit is contained in:
parent
af1a5f130b
commit
2b725a4db5
17
src/core.go
17
src/core.go
@ -224,12 +224,14 @@ func Run(opts *Options, revision string) {
|
|||||||
|
|
||||||
// Event coordination
|
// Event coordination
|
||||||
reading := true
|
reading := true
|
||||||
clearCache := false
|
clearCache := util.Once(false)
|
||||||
|
clearSelection := util.Once(false)
|
||||||
ticks := 0
|
ticks := 0
|
||||||
var nextCommand *string
|
var nextCommand *string
|
||||||
restart := func(command string) {
|
restart := func(command string) {
|
||||||
reading = true
|
reading = true
|
||||||
clearCache = true
|
clearCache = util.Once(true)
|
||||||
|
clearSelection = util.Once(true)
|
||||||
chunkList.Clear()
|
chunkList.Clear()
|
||||||
header = make([]string, 0, opts.HeaderLines)
|
header = make([]string, 0, opts.HeaderLines)
|
||||||
go reader.restart(command)
|
go reader.restart(command)
|
||||||
@ -262,10 +264,10 @@ func Run(opts *Options, revision string) {
|
|||||||
snapshot, count := chunkList.Snapshot()
|
snapshot, count := chunkList.Snapshot()
|
||||||
terminal.UpdateCount(count, !reading, value.(*string))
|
terminal.UpdateCount(count, !reading, value.(*string))
|
||||||
if opts.Sync {
|
if opts.Sync {
|
||||||
terminal.UpdateList(PassMerger(&snapshot, opts.Tac))
|
opts.Sync = false
|
||||||
|
terminal.UpdateList(PassMerger(&snapshot, opts.Tac), false)
|
||||||
}
|
}
|
||||||
matcher.Reset(snapshot, input(), false, !reading, sort, clearCache)
|
matcher.Reset(snapshot, input(), false, !reading, sort, clearCache())
|
||||||
clearCache = false
|
|
||||||
|
|
||||||
case EvtSearchNew:
|
case EvtSearchNew:
|
||||||
var command *string
|
var command *string
|
||||||
@ -284,8 +286,7 @@ func Run(opts *Options, revision string) {
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
snapshot, _ := chunkList.Snapshot()
|
snapshot, _ := chunkList.Snapshot()
|
||||||
matcher.Reset(snapshot, input(), true, !reading, sort, clearCache)
|
matcher.Reset(snapshot, input(), true, !reading, sort, clearCache())
|
||||||
clearCache = false
|
|
||||||
delay = false
|
delay = false
|
||||||
|
|
||||||
case EvtSearchProgress:
|
case EvtSearchProgress:
|
||||||
@ -327,7 +328,7 @@ func Run(opts *Options, revision string) {
|
|||||||
terminal.startChan <- true
|
terminal.startChan <- true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
terminal.UpdateList(val)
|
terminal.UpdateList(val, clearSelection())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -495,10 +495,13 @@ func (t *Terminal) UpdateProgress(progress float32) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// UpdateList updates Merger to display the list
|
// UpdateList updates Merger to display the list
|
||||||
func (t *Terminal) UpdateList(merger *Merger) {
|
func (t *Terminal) UpdateList(merger *Merger, reset bool) {
|
||||||
t.mutex.Lock()
|
t.mutex.Lock()
|
||||||
t.progress = 100
|
t.progress = 100
|
||||||
t.merger = merger
|
t.merger = merger
|
||||||
|
if reset {
|
||||||
|
t.selected = make(map[int32]selectedItem)
|
||||||
|
}
|
||||||
t.mutex.Unlock()
|
t.mutex.Unlock()
|
||||||
t.reqBox.Set(reqInfo, nil)
|
t.reqBox.Set(reqInfo, nil)
|
||||||
t.reqBox.Set(reqList, nil)
|
t.reqBox.Set(reqList, nil)
|
||||||
@ -2068,7 +2071,6 @@ func (t *Terminal) Loop() {
|
|||||||
command := replacePlaceholder(a.a,
|
command := replacePlaceholder(a.a,
|
||||||
t.ansi, t.delimiter, t.printsep, false, string(t.input), list)
|
t.ansi, t.delimiter, t.printsep, false, string(t.input), list)
|
||||||
newCommand = &command
|
newCommand = &command
|
||||||
t.selected = make(map[int32]selectedItem)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
|
@ -112,3 +112,13 @@ func DurWithin(
|
|||||||
func IsTty() bool {
|
func IsTty() bool {
|
||||||
return isatty.IsTerminal(os.Stdin.Fd())
|
return isatty.IsTerminal(os.Stdin.Fd())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Once returns a function that returns the specified boolean value only once
|
||||||
|
func Once(nextResponse bool) func() bool {
|
||||||
|
state := nextResponse
|
||||||
|
return func() bool {
|
||||||
|
prevState := state
|
||||||
|
state = false
|
||||||
|
return prevState
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -20,3 +20,21 @@ func TestContrain(t *testing.T) {
|
|||||||
t.Error("Expected", 3)
|
t.Error("Expected", 3)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestOnce(t *testing.T) {
|
||||||
|
o := Once(false)
|
||||||
|
if o() {
|
||||||
|
t.Error("Expected: false")
|
||||||
|
}
|
||||||
|
if o() {
|
||||||
|
t.Error("Expected: false")
|
||||||
|
}
|
||||||
|
|
||||||
|
o = Once(true)
|
||||||
|
if !o() {
|
||||||
|
t.Error("Expected: true")
|
||||||
|
}
|
||||||
|
if o() {
|
||||||
|
t.Error("Expected: false")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user