Skip to content

Commit

Permalink
Underscore boundaries should be ranked lower
Browse files Browse the repository at this point in the history
  • Loading branch information
junegunn committed Aug 16, 2024
1 parent c27c6dd commit 28004c2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/algo/algo.go
Original file line number Diff line number Diff line change
Expand Up @@ -879,6 +879,15 @@ func exactMatchNaive(caseSensitive bool, normalize bool, forward bool, boundaryC
eidx = lenRunes - (bestPos - lenPattern + 1)
}
score, _ := calculateScore(caseSensitive, normalize, text, pattern, sidx, eidx, false)
if boundaryCheck {
// Underscore boundaries should be ranked lower than the other types of boundaries
if sidx > 0 && text.Get(sidx-1) == '_' {
score--
}
if eidx < lenRunes && text.Get(eidx) == '_' {
score--
}
}
return Result{sidx, eidx, score}, nil
}
return Result{-1, -1, 0}, nil
Expand Down
8 changes: 8 additions & 0 deletions test/test_go.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3366,6 +3366,14 @@ def test_start_on_reload
tmux.send_keys :Space
tmux.until { |lines| assert_includes lines[-3], 'bar' }
end

def test_boundary_match
# Underscore boundaries should be ranked lower
assert_equal(
%w[[x] -x- _x- -x_ _x_],
`printf -- 'xxx\n-xx\nxx-\n_x_\n_x-\n-x_\n[x]\n-x-\n' | fzf -f"'x'"`.lines(chomp: true)
)
end
end

module TestShell
Expand Down

0 comments on commit 28004c2

Please sign in to comment.