File tree Expand file tree Collapse file tree 1 file changed +8
-3
lines changed
packages/cursorless-engine/src/util/allocateHats Expand file tree Collapse file tree 1 file changed +8
-3
lines changed Original file line number Diff line number Diff line change 11import { CompositeKeyMap , HatStability , TokenHat } from "@cursorless/common" ;
2- import { min } from "lodash" ;
2+ import { memoize , min } from "lodash" ;
33import { HatCandidate } from "./allocateHats" ;
44
55/**
@@ -50,8 +50,13 @@ export function minimumTokenRankContainingGrapheme(
5050 tokenRank : number ,
5151 graphemeTokenRanks : { [ key : string ] : number [ ] } ,
5252) : HatMetric {
53- return ( { grapheme : { text } } ) =>
54- min ( graphemeTokenRanks [ text ] . filter ( ( r ) => r > tokenRank ) ) ?? Infinity ;
53+ const coreMetric = memoize ( ( graphemeText : string ) : number => {
54+ return (
55+ min ( graphemeTokenRanks [ graphemeText ] . filter ( ( r ) => r > tokenRank ) ) ??
56+ Infinity
57+ ) ;
58+ } ) ;
59+ return ( { grapheme : { text } } ) => coreMetric ( text ) ;
5560}
5661
5762/**
You can’t perform that action at this time.
0 commit comments