diff --git a/src/algo/algo.go b/src/algo/algo.go index d6a9a663..cc855e1a 100644 --- a/src/algo/algo.go +++ b/src/algo/algo.go @@ -827,7 +827,7 @@ func exactMatchNaive(caseSensitive bool, normalize bool, forward bool, boundaryC // For simplicity, only look at the bonus at the first character position pidx := 0 - bestPos, bonus, bestBonus := -1, int16(0), int16(-1) + bestPos, bonus, bbonus, bestBonus := -1, int16(0), int16(0), int16(-1) for index := 0; index < lenRunes; index++ { index_ := indexAt(index, lenRunes, forward) char := text.Get(index_) @@ -849,7 +849,16 @@ func exactMatchNaive(caseSensitive bool, normalize bool, forward bool, boundaryC bonus = bonusAt(text, index_) } if boundaryCheck { - ok = bonus >= bonusBoundary + if forward && pidx_ == 0 { + bbonus = bonus + } else if !forward && pidx_ == lenPattern-1 { + if index_ < lenRunes-1 { + bbonus = bonusAt(text, index_+1) + } else { + bbonus = bonusBoundaryWhite + } + } + ok = bbonus >= bonusBoundary if ok && pidx_ == 0 { ok = index_ == 0 || charClassOf(text.Get(index_-1)) <= charDelimiter } diff --git a/test/test_filter.rb b/test/test_filter.rb index 3e604412..4a520442 100644 --- a/test/test_filter.rb +++ b/test/test_filter.rb @@ -304,11 +304,11 @@ class TestFilter < TestBase def test_boundary_match # Underscore boundaries should be ranked lower { - default: [' x '] + %w[/x/ [x] -x- -x_ _x- _x_], - path: ['/x/', ' x '] + %w[[x] -x- -x_ _x- _x_], - history: ['[x]', '-x-', ' x '] + %w[/x/ -x_ _x- _x_] + default: [' xyz '] + %w[/xyz/ [xyz] -xyz- -xyz_ _xyz- _xyz_], + path: ['/xyz/', ' xyz '] + %w[[xyz] -xyz- -xyz_ _xyz- _xyz_], + history: ['[xyz]', '-xyz-', ' xyz '] + %w[/xyz/ -xyz_ _xyz- _xyz_] }.each do |scheme, expected| - result = `printf -- 'xxx\n-xx\nxx-\n_x_\n_x-\n-x_\n[x]\n-x-\n x \n/x/\n' | #{FZF} -f"'x'" --scheme=#{scheme}`.lines(chomp: true) + result = `printf -- 'xxyzx\n-xxyz\nxyzx-\n_xyz_\n_xyz-\n-xyz_\n[xyz]\n-xyz-\n xyz \n/xyz/\n' | #{FZF} -f"'xyz'" --scheme=#{scheme}`.lines(chomp: true) assert_equal expected, result end end