MCPcopy
hub / github.com/VSCodeVim/Vim / ModeHandlerMapImpl

Class ModeHandlerMapImpl

src/mode/modeHandlerMap.ts:7–45  ·  view source on GitHub ↗

* Stores one ModeHandler (and therefore VimState) per TextDocument.

Source from the content-addressed store, hash-verified

5 * Stores one ModeHandler (and therefore VimState) per TextDocument.
6 */
7class ModeHandlerMapImpl {
8 private modeHandlerMap = new Map<Uri, ModeHandler>();
9
10 public async getOrCreate(editor: TextEditor): Promise<[ModeHandler, boolean]> {
11 const editorId = editor.document.uri;
12
13 let isNew = false;
14 let modeHandler: ModeHandler | undefined = this.get(editorId);
15
16 if (!modeHandler) {
17 isNew = true;
18 modeHandler = await ModeHandler.create(this, editor);
19 this.modeHandlerMap.set(editorId, modeHandler);
20 }
21 return [modeHandler, isNew];
22 }
23
24 public get(uri: Uri): ModeHandler | undefined {
25 return this.modeHandlerMap.get(uri);
26 }
27
28 public entries(): IterableIterator<[Uri, ModeHandler]> {
29 return this.modeHandlerMap.entries();
30 }
31
32 public delete(editorId: Uri) {
33 const modeHandler = this.modeHandlerMap.get(editorId);
34 if (modeHandler) {
35 modeHandler.dispose();
36 this.modeHandlerMap.delete(editorId);
37 }
38 }
39
40 public clear() {
41 for (const key of this.modeHandlerMap.keys()) {
42 this.delete(key);
43 }
44 }
45}
46
47export const ModeHandlerMap = new ModeHandlerMapImpl();

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected