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 1
1
import { CompositeKeyMap , HatStability , TokenHat } from "@cursorless/common" ;
2
- import { min } from "lodash" ;
2
+ import { memoize , min } from "lodash" ;
3
3
import { HatCandidate } from "./allocateHats" ;
4
4
5
5
/**
@@ -50,8 +50,13 @@ export function minimumTokenRankContainingGrapheme(
50
50
tokenRank : number ,
51
51
graphemeTokenRanks : { [ key : string ] : number [ ] } ,
52
52
) : 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 ) ;
55
60
}
56
61
57
62
/**
You can’t perform that action at this time.
0 commit comments