From 45112c85bee0d2748ca7dd4ebd811fac4be881a8 Mon Sep 17 00:00:00 2001 From: xconverge Date: Sat, 7 Oct 2017 16:33:43 -0700 Subject: [PATCH] Dispose modehandler if NO documents match the modehandler document anymore --- extension.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/extension.ts b/extension.ts index 3ca2662c7ec..39a9b160523 100644 --- a/extension.ts +++ b/extension.ts @@ -310,6 +310,21 @@ export async function activate(context: vscode.ExtensionContext) { }); }); + vscode.workspace.onDidCloseTextDocument(event => { + const documents = vscode.workspace.textDocuments; + + // Delete modehandler if vscode knows NOTHING about this document. This does + // not handle the case of the same file open twice. This only handles the + // case of deleting a modehandler once all tabs of this document have been + // closed + for (let mh in modeHandlerToEditorIdentity) { + const editor = modeHandlerToEditorIdentity[mh].vimState.editor.document; + if (documents.indexOf(editor) === -1) { + delete modeHandlerToEditorIdentity[mh]; + } + } + }); + registerCommand(context, 'toggleVim', async () => { Globals.active = !Globals.active; if (Globals.active) {