Skip to content

Commit

Permalink
Assign lastClosedModeHandler when onDidCloseTextDocument.
Browse files Browse the repository at this point in the history
  • Loading branch information
yaegaki committed Mar 27, 2019
1 parent 6a6816b commit f677af9
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,18 +170,28 @@ export async function activate(context: vscode.ExtensionContext) {
registerEventListener(
context,
vscode.workspace.onDidCloseTextDocument,
async () => {
async closedDocument => {
const documents = vscode.workspace.textDocuments;

// Delete modehandler once all tabs of this document have been closed
for (let editorIdentity of ModeHandlerMap.getKeys()) {
const modeHandler = ModeHandlerMap.get(editorIdentity);

if (
modeHandler == null ||
modeHandler.vimState.editor === undefined ||
documents.indexOf(modeHandler.vimState.editor.document) === -1
) {
let shouldDelete = false;

if (modeHandler == null || modeHandler.vimState.editor === undefined) {
shouldDelete = true;
} else {
const document = modeHandler.vimState.editor.document;
if (documents.indexOf(document) === -1) {
shouldDelete = true;
if (closedDocument === document) {
lastClosedModeHandler = modeHandler;
}
}
}

if (shouldDelete) {
ModeHandlerMap.delete(editorIdentity);
}
}
Expand Down

0 comments on commit f677af9

Please sign in to comment.