Skip to content
Myr

Fix exact boundary match with --scheme=path or --tiebreak end

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

Fix #4438

authored by Junegunn Choi · committed by Junegunn Choi · parent 5ed87ff · Browse files · 2 files+15 added−6 removed
This commit

State

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

Diff stats

2 files+15 added−6 removed

  • tests:+4 added−4 removed
  • other:+11 added−2 removed

2 files+15 added−6 removed

modified:src/algo/algo.go+11 added-2 removed
825 unmodified lines
826 }827828 // For simplicity, only look at the bonus at the first character position829 pidx := 0830 bestPos, bonus, bestBonus := -1, int16(0), int16(-1)830 bestPos, bonus, bbonus, bestBonus := -1, int16(0), int16(0), int16(-1)831 for index := 0; index < lenRunes; index++ {832 index_ := indexAt(index, lenRunes, forward)833 char := text.Get(index_)834 if !caseSensitive {
13 unmodified lines
848 if pidx_ == 0 {849 bonus = bonusAt(text, index_)850 }851 if boundaryCheck {852 if forward && pidx_ == 0 {853 bbonus = bonus854 } else if !forward && pidx_ == lenPattern-1 {855 if index_ < lenRunes-1 {856 bbonus = bonusAt(text, index_+1)857 } else {858 bbonus = bonusBoundaryWhite859 }860 }852 ok = bonus >= bonusBoundary861 ok = bbonus >= bonusBoundary862 if ok && pidx_ == 0 {863 ok = index_ == 0 || charClassOf(text.Get(index_-1)) <= charDelimiter864 }865 if ok && pidx_ == len(pattern)-1 {
167 unmodified lines
modified:test/test_filter.rb+4 added-4 removed
302 unmodified lines
303304 def test_boundary_match305 # Underscore boundaries should be ranked lower306 {307 default: [' x '] + %w[/x/ [x] -x- -x_ _x- _x_],308 path: ['/x/', ' x '] + %w[[x] -x- -x_ _x- _x_],309 history: ['[x]', '-x-', ' x '] + %w[/x/ -x_ _x- _x_]307 default: [' xyz '] + %w[/xyz/ [xyz] -xyz- -xyz_ _xyz- _xyz_],308 path: ['/xyz/', ' xyz '] + %w[[xyz] -xyz- -xyz_ _xyz- _xyz_],309 history: ['[xyz]', '-xyz-', ' xyz '] + %w[/xyz/ -xyz_ _xyz- _xyz_]310 }.each do |scheme, expected|311 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)311 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)312 assert_equal expected, result313 end314 end315end