@@ -463,17 +463,20 @@ export function fuzzyScore(pattern: string, word: string): [number, number[]] {
463463 let patternPos = patternStartPos ;
464464 let wordPos = 0 ;
465465
466+ // Run a simple check if the characters of pattern occur
467+ // (in order) at all in word. If that isn't the case we
468+ // stop because no match will be possible
466469 while ( patternPos < patternLen && wordPos < wordLen ) {
467470 if ( lowPattern [ patternPos ] === lowWord [ wordPos ] ) {
468471 patternPos += 1 ;
469472 }
470473 wordPos += 1 ;
471474 }
472475 if ( patternPos !== patternLen ) {
473- // no simple matches found -> return early
474476 return undefined ;
475477 }
476478
479+ // There will be a mach, fill in tables
477480 for ( patternPos = patternStartPos + 1 ; patternPos <= patternLen ; patternPos ++ ) {
478481
479482 let lastLowWordChar = '' ;
@@ -483,20 +486,22 @@ export function fuzzyScore(pattern: string, word: string): [number, number[]] {
483486 let score = - 1 ;
484487 let lowWordChar = lowWord [ wordPos - 1 ] ;
485488 if ( lowPattern [ patternPos - 1 ] === lowWordChar ) {
486-
487- if ( wordPos === 1 ) {
489+ if ( wordPos === ( patternPos - patternStartPos ) ) {
490+ // common prefix: `foobar <-> foobaz`
488491 if ( pattern [ patternPos - 1 ] === word [ wordPos - 1 ] ) {
489492 score = 7 ;
490493 } else {
491494 score = 5 ;
492495 }
493496 } else if ( lowWordChar !== word [ wordPos - 1 ] ) {
497+ // hitting upper-case: `foo <-> forOthers`
494498 if ( pattern [ patternPos - 1 ] === word [ wordPos - 1 ] ) {
495499 score = 7 ;
496500 } else {
497501 score = 5 ;
498502 }
499503 } else if ( _seps [ lastLowWordChar ] ) {
504+ // post separator: `foo <-> bar_foo`
500505 score = 5 ;
501506
502507 } else {
0 commit comments