Skip to content

Commit

Permalink
Assign lastClosedModeHandler when onDidCloseTextDocument. (#3630)
Browse files Browse the repository at this point in the history
fixes #3507
  • Loading branch information
yaegaki authored and jpoon committed Apr 2, 2019
1 parent 0d02851 commit 6b812d4
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 6b812d4

Please sign in to comment.