MCPcopy Create free account
hub / github.com/cursorless-dev/cursorless / IndividualHatMap

Class IndividualHatMap

src/core/IndividualHatMap.ts:11–82  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

9}
10
11export class IndividualHatMap implements ReadOnlyHatMap {
12 private isExpired: boolean = false;
13 private documentTokenLists: Map<string, Token[]> = new Map();
14 private deregisterFunctions: (() => void)[] = [];
15
16 private map: {
17 [decoratedCharacter: string]: Token;
18 } = {};
19
20 constructor(private graph: Graph) {}
21
22 private getDocumentTokenList(document: TextDocument) {
23 const key = document.uri.toString();
24 let currentValue = this.documentTokenLists.get(key);
25
26 if (currentValue == null) {
27 currentValue = [];
28 this.documentTokenLists.set(key, currentValue);
29 this.deregisterFunctions.push(
30 this.graph.rangeUpdater.registerRangeInfoList(document, currentValue)
31 );
32 }
33
34 return currentValue;
35 }
36
37 clone() {
38 const ret = new IndividualHatMap(this.graph);
39
40 this.getEntries().forEach(([key, token]) => {
41 ret.addTokenByKey(key, { ...token });
42 });
43
44 return ret;
45 }
46
47 getEntries() {
48 this.checkExpired();
49 return Object.entries(this.map);
50 }
51
52 private addTokenByKey(key: string, token: Token) {
53 this.map[key] = token;
54 this.getDocumentTokenList(token.editor.document).push(token);
55 }
56
57 addToken(hatStyle: HatStyleName, character: string, token: Token) {
58 this.addTokenByKey(HatTokenMap.getKey(hatStyle, character), token);
59 }
60
61 getToken(hatStyle: HatStyleName, character: string) {
62 this.checkExpired();
63 return this.map[HatTokenMap.getKey(hatStyle, character)];
64 }
65
66 clear() {
67 this.map = {};
68 this.documentTokenLists = new Map();

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected