Skip to content
Myr

Defer resetting multi-selection on reload

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

authored by Junegunn Choi · committed by Junegunn Choi · parent af1a5f1 · Browse files · 4 files+41 added−10 removed
This commit

State

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

Diff stats

4 files+41 added−10 removed

  • other:+41 added−10 removed

4 files+41 added−10 removed

modified:src/util/util_test.go+18 added
18 unmodified lines
19 if Constrain(5, -1, 3) != 3 {20 t.Error("Expected", 3)21 }22}2324func TestOnce(t *testing.T) {25 o := Once(false)26 if o() {27 t.Error("Expected: false")28 }29 if o() {30 t.Error("Expected: false")31 }3233 o = Once(true)34 if !o() {35 t.Error("Expected: true")36 }37 if o() {38 t.Error("Expected: false")39 }40}
modified:src/util/util.go+10 added
110 unmodified lines
111// IsTty returns true is stdin is a terminal112func IsTty() bool {113 return isatty.IsTerminal(os.Stdin.Fd())114}115116// Once returns a function that returns the specified boolean value only once117func Once(nextResponse bool) func() bool {118 state := nextResponse119 return func() bool {120 prevState := state121 state = false122 return prevState123 }124}
modified:src/core.go+9 added-8 removed
222 unmodified lines
223 }224225 // Event coordination226 reading := true227 clearCache := false227 clearCache := util.Once(false)228 clearSelection := util.Once(false)229 ticks := 0230 var nextCommand *string231 restart := func(command string) {232 reading = true232 clearCache = true233 clearCache = util.Once(true)234 clearSelection = util.Once(true)235 chunkList.Clear()236 header = make([]string, 0, opts.HeaderLines)237 go reader.restart(command)238 }
24 unmodified lines
263 }264 snapshot, count := chunkList.Snapshot()265 terminal.UpdateCount(count, !reading, value.(*string))266 if opts.Sync {267 opts.Sync = false265 terminal.UpdateList(PassMerger(&snapshot, opts.Tac))268 terminal.UpdateList(PassMerger(&snapshot, opts.Tac), false)269 }267 matcher.Reset(snapshot, input(), false, !reading, sort, clearCache)268 clearCache = false270 matcher.Reset(snapshot, input(), false, !reading, sort, clearCache())271272 case EvtSearchNew:273 var command *string274 switch val := value.(type) {
10 unmodified lines
285 }286 break287 }288 snapshot, _ := chunkList.Snapshot()287 matcher.Reset(snapshot, input(), true, !reading, sort, clearCache)288 clearCache = false289 matcher.Reset(snapshot, input(), true, !reading, sort, clearCache())290 delay = false291292 case EvtSearchProgress:293 switch val := value.(type) {
33 unmodified lines
327 deferred = false328 terminal.startChan <- true329 }330 }330 terminal.UpdateList(val)331 terminal.UpdateList(val, clearSelection())332 }333 }334 }335 events.Clear()
9 unmodified lines
modified:src/terminal.go+4 added-2 removed
493 unmodified lines
494 }495}496497// UpdateList updates Merger to display the list498func (t *Terminal) UpdateList(merger *Merger) {498func (t *Terminal) UpdateList(merger *Merger, reset bool) {499 t.mutex.Lock()500 t.progress = 100501 t.merger = merger502 if reset {503 t.selected = make(map[int32]selectedItem)504 }505 t.mutex.Unlock()506 t.reqBox.Set(reqInfo, nil)507 t.reqBox.Set(reqList, nil)508}
1561 unmodified lines
2070 if valid {2071 command := replacePlaceholder(a.a,2072 t.ansi, t.delimiter, t.printsep, false, string(t.input), list)2073 newCommand = &command2071 t.selected = make(map[int32]selectedItem)2074 }2075 }2076 return true2077 }
104 unmodified lines