@@ -46,7 +46,7 @@ export function filterOptions(
4646 } ) )
4747 // Only include matches of the entire substring, with a slight
4848 // affordance for transposition or extra characters.
49- . filter ( ( pair ) => pair . score >= cleanFilter . length - 2 )
49+ . filter ( ( pair ) => pair . score >= Math . max ( cleanFilter . length - 2 , cleanFilter . length ) /** Filter text might have length less than 2 */ )
5050 // Sort 'em by order of their score.
5151 . sort ( ( a , b ) => b . score - a . score )
5252 // …and grab the original Options back from their pairs.
@@ -69,8 +69,8 @@ export function filterOptions(
6969 * closer matches.
7070 */
7171export function typeaheadSimilarity ( a : string , b : string ) : number {
72- const aLength = a . length ;
73- const bLength = b . length ;
72+ let aLength = a . length ;
73+ let bLength = b . length ;
7474 const table : any [ ] = [ ] ;
7575
7676 if ( ! aLength || ! bLength ) {
@@ -80,6 +80,8 @@ export function typeaheadSimilarity(a: string, b: string): number {
8080 // Ensure `a` isn't shorter than `b`.
8181 if ( aLength < bLength ) {
8282 [ a , b ] = [ b , a ] ;
83+ // Swap the length of these strings.
84+ [ aLength , bLength ] = [ bLength , aLength ] ;
8385 }
8486
8587 // Early exit if `a` includes `b`; these will be scored higher than any
0 commit comments