Skip to content

Commit

Permalink
fzf-v2: fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
noib3 committed Oct 27, 2023
1 parent 268d215 commit 15155c9
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
7 changes: 4 additions & 3 deletions src/algos/fzf/scheme.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,13 @@ impl FzfScheme {
}

/// TODO: docs
#[doc(hidden)]
#[derive(Clone)]
pub(super) struct Scheme {
pub struct Scheme {
pub bonus_boundary_white: Score,
pub bonus_boundary_delimiter: Score,
pub initial_char_class: CharClass,
pub is_delimiter: fn(char) -> bool,
pub(super) initial_char_class: CharClass,
pub(super) is_delimiter: fn(char) -> bool,
}

impl Default for Scheme {
Expand Down
14 changes: 10 additions & 4 deletions src/algos/fzf/v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ impl FzfV2 {
Self::default()
}

/// TODO: docs
#[cfg(feature = "tests")]
pub fn scheme(&self) -> &Scheme {
&self.scheme
}

/// TODO: docs
#[inline]
pub fn with_case_sensitivity(
Expand Down Expand Up @@ -315,11 +321,11 @@ where
.zip(scoring_matrix.cols(left_of_starting_col))
.zip(scoring_matrix.cols(up_left_of_starting_col));

let candidate = candidate.slice(matched_idx..last_matched_idx);

let mut is_in_gap = false;

for (char_idx, candidate_char) in candidate.char_idxs() {
for (char_idx, candidate_char) in
candidate.slice(matched_idx..last_matched_idx).char_idxs()
{
let ((cell, left_cell), up_left_cell) = cols.next().unwrap();

let score_left =
Expand All @@ -341,7 +347,7 @@ where

if consecutive > 1 {
let fb = bonus_vector[CandidateCharIdx(
char_idx.into_usize() - consecutive + 1,
char_idx.into_usize() + 1 - consecutive,
)];

if bonus >= bonus::BOUNDARY && bonus > fb {
Expand Down
7 changes: 4 additions & 3 deletions tests/fzf_v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ fn fzf_v2_score_1() {

assert_eq!(
mach.distance().into_score(),
bonus::MATCH * 5 + bonus::CAMEL_123
- penalty::GAP_START
- penalty::GAP_EXTENSION * 3
bonus::MATCH * 5
+ fzf.scheme().bonus_boundary_white
* bonus::FIRST_QUERY_CHAR_MULTIPLIER
+ fzf.scheme().bonus_boundary_white * 4
);

assert_eq!(mach.matched_ranges().sorted(), [0..5]);
Expand Down

0 comments on commit 15155c9

Please sign in to comment.