@@ -45,7 +45,7 @@ pub struct Command {
45
45
pub selected : bool ,
46
46
pub dir : Option < String > ,
47
47
pub features : Features ,
48
- pub match_bounds : Vec < ( usize , usize ) > ,
48
+ pub match_indices : Vec < usize > ,
49
49
}
50
50
51
51
#[ derive( Debug , Clone , Serialize ) ]
@@ -331,7 +331,7 @@ impl History {
331
331
rank : row. get ( 8 ) . unwrap_or_else ( |err| {
332
332
panic ! ( "McFly error: rank to be readable ({err})" )
333
333
} ) ,
334
- match_bounds : bounds,
334
+ match_indices : bounds,
335
335
features : Features {
336
336
age_factor : row. get ( 9 ) . unwrap_or_else ( |err| {
337
337
panic ! ( "McFly error: age_factor to be readable ({err})" )
@@ -409,10 +409,19 @@ impl History {
409
409
// the likelihood of the weight flipping the outcome for
410
410
// the originally lower-ranked result.
411
411
412
- let a_start = a. match_bounds [ 0 ] . 0 ;
413
- let b_start = b. match_bounds [ 0 ] . 0 ;
414
- let a_len = a. match_bounds [ 0 ] . 1 - a_start;
415
- let b_len = b. match_bounds [ 0 ] . 1 - b_start;
412
+ let a_start = * a. match_indices . first ( ) . unwrap ( ) ;
413
+ let b_start = * b. match_indices . first ( ) . unwrap ( ) ;
414
+
415
+ let a_len = if fuzzy > 0 {
416
+ a. match_indices . last ( ) . unwrap ( ) + 1 - a_start
417
+ } else {
418
+ cmd. len ( )
419
+ } ;
420
+ let b_len = if fuzzy > 0 {
421
+ b. match_indices . last ( ) . unwrap ( ) + 1 - b_start
422
+ } else {
423
+ cmd. len ( )
424
+ } ;
416
425
417
426
let a_mod =
418
427
1.0 - ( a_start + a_len) as f64 / ( a_start + b_start + a_len + b_len) as f64 ;
@@ -436,7 +445,7 @@ impl History {
436
445
cmd. chars ( ) . any ( |c| c. is_uppercase ( ) )
437
446
}
438
447
439
- fn calc_match_bounds ( text : & str , cmd : & str , fuzzy : i16 ) -> Vec < ( usize , usize ) > {
448
+ fn calc_match_bounds ( text : & str , cmd : & str , fuzzy : i16 ) -> Vec < usize > {
440
449
let ( text, cmd) = if Self :: is_case_sensitive ( cmd) {
441
450
( text. to_string ( ) , cmd. to_string ( ) )
442
451
} else {
@@ -446,28 +455,24 @@ impl History {
446
455
match fuzzy {
447
456
0 => text
448
457
. match_indices ( & cmd)
449
- . map ( |( index, _) | ( index, index + cmd. len ( ) ) )
450
- . collect :: < Vec < _ > > ( ) ,
458
+ . flat_map ( |( index, _) | index.. index + cmd. len ( ) )
459
+ . collect ( ) ,
451
460
_ => {
452
461
let mut search_iter = cmd. chars ( ) . peekable ( ) ;
453
- let mut matches = text
454
- . match_indices ( |c| {
455
- let next = search_iter. peek ( ) ;
456
-
457
- if next. is_some ( ) && next. unwrap ( ) == & c {
458
- let _advance = search_iter. next ( ) ;
459
462
460
- return true ;
461
- }
463
+ text . match_indices ( |c| {
464
+ let next = search_iter . peek ( ) ;
462
465
463
- false
464
- } )
465
- . map ( |m| m. 0 ) ;
466
+ if next. is_some ( ) && next. unwrap ( ) == & c {
467
+ let _advance = search_iter. next ( ) ;
466
468
467
- let start = matches . next ( ) . unwrap_or ( 0 ) ;
468
- let end = matches . last ( ) . unwrap_or ( start ) + 1 ;
469
+ return true ;
470
+ }
469
471
470
- vec ! [ ( start, end) ]
472
+ false
473
+ } )
474
+ . map ( |m| m. 0 )
475
+ . collect ( )
471
476
}
472
477
}
473
478
}
0 commit comments