Projects STRLCPY fzf Commits 38259d03
🤬
  • ■ ■ ■ ■ ■ ■
    CHANGELOG.md
    1 1  CHANGELOG
    2 2  =========
    3 3   
     4 +0.32.1
     5 +------
     6 +- Fixed incorrect ordering of `--tiebreak=chunk`
     7 + 
    4 8  0.32.0
    5 9  ------
    6 10  - Updated the scoring algorithm
    skipped 1270 lines
  • ■ ■ ■ ■ ■ ■
    src/core.go
    skipped 145 lines
    146 146   
    147 147   // Matcher
    148 148   forward := true
    149  - for _, cri := range opts.Criteria[1:] {
    150  - if cri == byEnd {
     149 + withPos := false
     150 + for idx := len(opts.Criteria) - 1; idx > 0; idx-- {
     151 + switch opts.Criteria[idx] {
     152 + case byChunk:
     153 + withPos = true
     154 + case byEnd:
    151 155   forward = false
    152  - break
    153  - }
    154  - if cri == byBegin {
    155  - break
     156 + case byBegin:
     157 + forward = true
    156 158   }
    157 159   }
    158 160   patternBuilder := func(runes []rune) *Pattern {
    159 161   return BuildPattern(
    160  - opts.Fuzzy, opts.FuzzyAlgo, opts.Extended, opts.Case, opts.Normalize, forward,
     162 + opts.Fuzzy, opts.FuzzyAlgo, opts.Extended, opts.Case, opts.Normalize, forward, withPos,
    161 163   opts.Filter == nil, opts.Nth, opts.Delimiter, runes)
    162 164   }
    163 165   matcher := NewMatcher(patternBuilder, sort, opts.Tac, eventBox)
    skipped 193 lines
  • ■ ■ ■ ■ ■ ■
    src/pattern.go
    skipped 50 lines
    51 51   caseSensitive bool
    52 52   normalize bool
    53 53   forward bool
     54 + withPos bool
    54 55   text []rune
    55 56   termSets []termSet
    56 57   sortable bool
    skipped 28 lines
    85 86   
    86 87  // BuildPattern builds Pattern object from the given arguments
    87 88  func BuildPattern(fuzzy bool, fuzzyAlgo algo.Algo, extended bool, caseMode Case, normalize bool, forward bool,
    88  - cacheable bool, nth []Range, delimiter Delimiter, runes []rune) *Pattern {
     89 + withPos bool, cacheable bool, nth []Range, delimiter Delimiter, runes []rune) *Pattern {
    89 90   
    90 91   var asString string
    91 92   if extended {
    skipped 53 lines
    145 146   caseSensitive: caseSensitive,
    146 147   normalize: normalize,
    147 148   forward: forward,
     149 + withPos: withPos,
    148 150   text: []rune(asString),
    149 151   termSets: termSets,
    150 152   sortable: sortable,
    skipped 151 lines
    302 304   
    303 305   if space == nil {
    304 306   for idx := 0; idx < chunk.count; idx++ {
    305  - if match, _, _ := p.MatchItem(&chunk.items[idx], false, slab); match != nil {
     307 + if match, _, _ := p.MatchItem(&chunk.items[idx], p.withPos, slab); match != nil {
    306 308   matches = append(matches, *match)
    307 309   }
    308 310   }
    309 311   } else {
    310 312   for _, result := range space {
    311  - if match, _, _ := p.MatchItem(result.item, false, slab); match != nil {
     313 + if match, _, _ := p.MatchItem(result.item, p.withPos, slab); match != nil {
    312 314   matches = append(matches, *match)
    313 315   }
    314 316   }
    skipped 112 lines
  • ■ ■ ■ ■ ■ ■
    src/pattern_test.go
    skipped 66 lines
    67 67  func TestExact(t *testing.T) {
    68 68   defer clearPatternCache()
    69 69   clearPatternCache()
    70  - pattern := BuildPattern(true, algo.FuzzyMatchV2, true, CaseSmart, false, true, true,
     70 + pattern := BuildPattern(true, algo.FuzzyMatchV2, true, CaseSmart, false, true, false, true,
    71 71   []Range{}, Delimiter{}, []rune("'abc"))
    72 72   chars := util.ToChars([]byte("aabbcc abc"))
    73 73   res, pos := algo.ExactMatchNaive(
    skipped 9 lines
    83 83  func TestEqual(t *testing.T) {
    84 84   defer clearPatternCache()
    85 85   clearPatternCache()
    86  - pattern := BuildPattern(true, algo.FuzzyMatchV2, true, CaseSmart, false, true, true, []Range{}, Delimiter{}, []rune("^AbC$"))
     86 + pattern := BuildPattern(true, algo.FuzzyMatchV2, true, CaseSmart, false, true, false, true, []Range{}, Delimiter{}, []rune("^AbC$"))
    87 87   
    88 88   match := func(str string, sidxExpected int, eidxExpected int) {
    89 89   chars := util.ToChars([]byte(str))
    skipped 16 lines
    106 106  func TestCaseSensitivity(t *testing.T) {
    107 107   defer clearPatternCache()
    108 108   clearPatternCache()
    109  - pat1 := BuildPattern(true, algo.FuzzyMatchV2, false, CaseSmart, false, true, true, []Range{}, Delimiter{}, []rune("abc"))
     109 + pat1 := BuildPattern(true, algo.FuzzyMatchV2, false, CaseSmart, false, true, false, true, []Range{}, Delimiter{}, []rune("abc"))
    110 110   clearPatternCache()
    111  - pat2 := BuildPattern(true, algo.FuzzyMatchV2, false, CaseSmart, false, true, true, []Range{}, Delimiter{}, []rune("Abc"))
     111 + pat2 := BuildPattern(true, algo.FuzzyMatchV2, false, CaseSmart, false, true, false, true, []Range{}, Delimiter{}, []rune("Abc"))
    112 112   clearPatternCache()
    113  - pat3 := BuildPattern(true, algo.FuzzyMatchV2, false, CaseIgnore, false, true, true, []Range{}, Delimiter{}, []rune("abc"))
     113 + pat3 := BuildPattern(true, algo.FuzzyMatchV2, false, CaseIgnore, false, true, false, true, []Range{}, Delimiter{}, []rune("abc"))
    114 114   clearPatternCache()
    115  - pat4 := BuildPattern(true, algo.FuzzyMatchV2, false, CaseIgnore, false, true, true, []Range{}, Delimiter{}, []rune("Abc"))
     115 + pat4 := BuildPattern(true, algo.FuzzyMatchV2, false, CaseIgnore, false, true, false, true, []Range{}, Delimiter{}, []rune("Abc"))
    116 116   clearPatternCache()
    117  - pat5 := BuildPattern(true, algo.FuzzyMatchV2, false, CaseRespect, false, true, true, []Range{}, Delimiter{}, []rune("abc"))
     117 + pat5 := BuildPattern(true, algo.FuzzyMatchV2, false, CaseRespect, false, true, false, true, []Range{}, Delimiter{}, []rune("abc"))
    118 118   clearPatternCache()
    119  - pat6 := BuildPattern(true, algo.FuzzyMatchV2, false, CaseRespect, false, true, true, []Range{}, Delimiter{}, []rune("Abc"))
     119 + pat6 := BuildPattern(true, algo.FuzzyMatchV2, false, CaseRespect, false, true, false, true, []Range{}, Delimiter{}, []rune("Abc"))
    120 120   
    121 121   if string(pat1.text) != "abc" || pat1.caseSensitive != false ||
    122 122   string(pat2.text) != "Abc" || pat2.caseSensitive != true ||
    skipped 6 lines
    129 129  }
    130 130   
    131 131  func TestOrigTextAndTransformed(t *testing.T) {
    132  - pattern := BuildPattern(true, algo.FuzzyMatchV2, true, CaseSmart, false, true, true, []Range{}, Delimiter{}, []rune("jg"))
     132 + pattern := BuildPattern(true, algo.FuzzyMatchV2, true, CaseSmart, false, true, false, true, []Range{}, Delimiter{}, []rune("jg"))
    133 133   tokens := Tokenize("junegunn", Delimiter{})
    134 134   trans := Transform(tokens, []Range{{1, 1}})
    135 135   
    skipped 28 lines
    164 164  func TestCacheKey(t *testing.T) {
    165 165   test := func(extended bool, patStr string, expected string, cacheable bool) {
    166 166   clearPatternCache()
    167  - pat := BuildPattern(true, algo.FuzzyMatchV2, extended, CaseSmart, false, true, true, []Range{}, Delimiter{}, []rune(patStr))
     167 + pat := BuildPattern(true, algo.FuzzyMatchV2, extended, CaseSmart, false, true, false, true, []Range{}, Delimiter{}, []rune(patStr))
    168 168   if pat.CacheKey() != expected {
    169 169   t.Errorf("Expected: %s, actual: %s", expected, pat.CacheKey())
    170 170   }
    skipped 17 lines
    188 188  func TestCacheable(t *testing.T) {
    189 189   test := func(fuzzy bool, str string, expected string, cacheable bool) {
    190 190   clearPatternCache()
    191  - pat := BuildPattern(fuzzy, algo.FuzzyMatchV2, true, CaseSmart, true, true, true, []Range{}, Delimiter{}, []rune(str))
     191 + pat := BuildPattern(fuzzy, algo.FuzzyMatchV2, true, CaseSmart, true, true, false, true, []Range{}, Delimiter{}, []rune(str))
    192 192   if pat.CacheKey() != expected {
    193 193   t.Errorf("Expected: %s, actual: %s", expected, pat.CacheKey())
    194 194   }
    skipped 16 lines
  • ■ ■ ■ ■ ■
    test/test_go.rb
    skipped 755 lines
    756 756   
    757 757   def test_tiebreak_chunk
    758 758   writelines(tempname, [
    759  - '1 foobarbaz baz',
     759 + '1 foobarbaz ba',
    760 760   '2 foobar baz',
    761 761   '3 foo barbaz'
    762 762   ])
    skipped 1 lines
    764 764   assert_equal [
    765 765   '3 foo barbaz',
    766 766   '2 foobar baz',
    767  - '1 foobarbaz baz'
     767 + '1 foobarbaz ba'
    768 768   ], `#{FZF} -fo --tiebreak=chunk < #{tempname}`.lines(chomp: true)
     769 + 
     770 + assert_equal [
     771 + '1 foobarbaz ba',
     772 + '2 foobar baz',
     773 + '3 foo barbaz'
     774 + ], `#{FZF} -fba --tiebreak=chunk < #{tempname}`.lines(chomp: true)
    769 775   end
    770 776   
    771 777   def test_invalid_cache
    skipped 1953 lines
Please wait...
Page is in error, reload to recover