Skip to content
Myr

Fix selection lost on revision bump

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 d364a11 · Browse files · 6 files+56 added−11 removed
This commit

State

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

Diff stats

6 files+56 added−11 removed

  • tests:+33 added−0 removed
  • other:+23 added−11 removed

6 files+56 added−11 removed

modified:src/chunklist.go+7 added
39 unmodified lines
40func (c *Chunk) IsFull() bool {41 return c.count == chunkSize42}4344func (c *Chunk) lastIndex(minValue int32) int32 {45 if c.count == 0 {46 return minValue47 }48 return c.items[c.count-1].Index() + 1 // Exclusive49}5051func (cl *ChunkList) lastChunk() *Chunk {52 return cl.chunks[len(cl.chunks)-1]53}54
87 unmodified lines
modified:src/matcher.go+2 added-1 removed
163 unmodified lines
164 return PassMerger(&request.chunks, m.tac, request.revision), false165 }166167 minIndex := request.chunks[0].items[0].Index()168 maxIndex := request.chunks[numChunks-1].lastIndex(minIndex)169 cancelled := util.NewAtomicBool(false)170171 slices := m.sliceChunks(request.chunks)172 numSlices := len(slices)
63 unmodified lines
236 for range slices {237 partialResult := <-resultChan238 partialResults[partialResult.index] = partialResult.matches239 }239 return NewMerger(pattern, partialResults, m.sort && request.pattern.sortable, m.tac, request.revision, minIndex), false240 return NewMerger(pattern, partialResults, m.sort && request.pattern.sortable, m.tac, request.revision, minIndex, maxIndex), false241}242243// Reset is called to interrupt/signal the ongoing search244func (m *Matcher) Reset(chunks []*Chunk, patternRunes []rune, cancel bool, final bool, sort bool, revision revision) {
14 unmodified lines
modified:src/merger_test.go+3 added-3 removed
56 unmodified lines
57 lists, items := buildLists(false)58 cnt := len(items)5960 // Not sorted: same order61 mg := NewMerger(nil, lists, false, false, revision{}, 0)61 mg := NewMerger(nil, lists, false, false, revision{}, 0, 0)62 assert(t, cnt == mg.Length(), "Invalid Length")63 for i := 0; i < cnt; i++ {64 assert(t, items[i] == mg.Get(i), "Invalid Get")65 }
3 unmodified lines
69 lists, items := buildLists(true)70 cnt := len(items)7172 // Sorted sorted order73 mg := NewMerger(nil, lists, true, false, revision{}, 0)73 mg := NewMerger(nil, lists, true, false, revision{}, 0, 0)74 assert(t, cnt == mg.Length(), "Invalid Length")75 sort.Sort(ByRelevance(items))76 for i := 0; i < cnt; i++ {77 if items[i] != mg.Get(i) {
1 unmodified line
79 }80 }8182 // Inverse order83 mg2 := NewMerger(nil, lists, true, false, revision{}, 0)83 mg2 := NewMerger(nil, lists, true, false, revision{}, 0, 0)84 for i := cnt - 1; i >= 0; i-- {85 if items[i] != mg2.Get(i) {86 t.Error("Not sorted", items[i], mg2.Get(i))87 }
2 unmodified lines
modified:src/merger.go+9 added-5 removed
2 unmodified lines
3import "fmt"45// EmptyMerger is a Merger with no data6func EmptyMerger(revision revision) *Merger {7 return NewMerger(nil, [][]Result{}, false, false, revision, 0)7 return NewMerger(nil, [][]Result{}, false, false, revision, 0, 0)8}910// Merger holds a set of locally sorted lists of items and provides the view of11// a single, globally-sorted list
9 unmodified lines
21 count int22 pass bool23 revision revision24 minIndex int3225 maxIndex int3226}2728// PassMerger returns a new Merger that simply returns the items in the29// original order30func PassMerger(chunks *[]*Chunk, tac bool, revision revision) *Merger {30 var minIndex int3231 var minIndex, maxIndex int3232 if len(*chunks) > 0 {33 minIndex = (*chunks)[0].items[0].Index()34 maxIndex = (*chunks)[len(*chunks)-1].lastIndex(minIndex)35 }36 mg := Merger{37 pattern: nil,38 chunks: chunks,39 tac: tac,40 count: 0,41 pass: true,42 revision: revision,41 minIndex: minIndex}43 minIndex: minIndex,44 maxIndex: maxIndex}4546 for _, chunk := range *mg.chunks {47 mg.count += chunk.count48 }49 return &mg50}5152// NewMerger returns a new Merger50func NewMerger(pattern *Pattern, lists [][]Result, sorted bool, tac bool, revision revision, minIndex int32) *Merger {53func NewMerger(pattern *Pattern, lists [][]Result, sorted bool, tac bool, revision revision, minIndex int32, maxIndex int32) *Merger {54 mg := Merger{55 pattern: pattern,56 lists: lists,57 merged: []Result{},
3 unmodified lines
61 tac: tac,62 final: false,63 count: 0,64 revision: revision,62 minIndex: minIndex}65 minIndex: minIndex,66 maxIndex: maxIndex}6768 for _, list := range mg.lists {69 mg.count += len(list)70 }
106 unmodified lines
modified:src/terminal.go+2 added-2 removed
1678 unmodified lines
1679 } else {1680 // Trimmed by --tail: filter selection by index1681 filtered := make(map[int32]selectedItem)1682 minIndex := merger.minIndex1683 maxIndex := minIndex + int32(merger.Length())1683 maxIndex := merger.maxIndex1684 for k, v := range t.selected {1685 var included bool1686 if maxIndex > minIndex {1687 included = k >= minIndex && k < maxIndex1688 } else { // int32 overflow [==> <==]1688 } else if maxIndex < minIndex { // int32 overflow [==> <==]1689 included = k >= minIndex || k < maxIndex1690 }1691 if included {1692 filtered[k] = v
5236 unmodified lines
modified:test/test_core.rb+33 added
2000 unmodified lines
2001 tmux.send_keys :Tab2002 tmux.until { assert_equal 0, it.select_count }2003 tmux.until { refute it.any_include?('Selected') }2004 end20052006 def test_preserve_selection_on_revision_bump2007 tmux.send_keys %(seq 100 | #{FZF} --multi --sync --query "'1" --bind 'a:select-all+change-header(pressed a),b:change-header(pressed b)+change-nth(1),c:exclude'), :Enter2008 tmux.until do2009 assert_equal 20, it.match_count2010 assert_equal 0, it.select_count2011 end2012 tmux.send_keys :a2013 tmux.until do2014 assert_equal 20, it.match_count2015 assert_equal 20, it.select_count2016 assert it.any_include?('pressed a')2017 end2018 tmux.send_keys :b2019 tmux.until do2020 assert_equal 20, it.match_count2021 assert_equal 20, it.select_count2022 refute it.any_include?('pressed a')2023 assert it.any_include?('pressed b')2024 end2025 tmux.send_keys :a2026 tmux.until do2027 assert_equal 20, it.match_count2028 assert_equal 20, it.select_count2029 assert it.any_include?('pressed a')2030 refute it.any_include?('pressed b')2031 end2032 tmux.send_keys :c2033 tmux.until do2034 assert_equal 19, it.match_count2035 assert_equal 19, it.select_count2036 end2037 end2038end