We weren't properly disposing our listeners. This caused all sorts of
bad things to happen.
This commit is contained in:
johnfn 2016-10-11 18:53:52 -07:00
parent c62fda4ac3
commit 734d67c8be
2 changed files with 26 additions and 4 deletions

View File

@ -150,8 +150,12 @@ export async function activate(context: vscode.ExtensionContext) {
}); });
vscode.workspace.onDidCloseTextDocument((event) => { vscode.workspace.onDidCloseTextDocument((event) => {
const key = event.fileName + vscode.window.activeTextEditor.viewColumn;
modeHandlerToEditorIdentity[key].dispose();
// Remove modehandler for closed document // Remove modehandler for closed document
delete modeHandlerToEditorIdentity[event.fileName + vscode.window.activeTextEditor.viewColumn]; delete modeHandlerToEditorIdentity[key];
}); });
registerCommand(context, 'type', async (args) => { registerCommand(context, 'type', async (args) => {

View File

@ -53,6 +53,10 @@ export class ViewChange {
* indicate what they want to do. * indicate what they want to do.
*/ */
export class VimState { export class VimState {
private _id = Math.floor(Math.random() * 10000) % 10000;
public get id(): number { return this._id; }
/** /**
* The column the cursor wants to be at, or Number.POSITIVE_INFINITY if it should always * The column the cursor wants to be at, or Number.POSITIVE_INFINITY if it should always
* be the rightmost column. * be the rightmost column.
@ -159,7 +163,15 @@ export class VimState {
/** /**
* The mode Vim will be in once this action finishes. * The mode Vim will be in once this action finishes.
*/ */
public currentMode = ModeName.Normal; private _currentMode = ModeName.Normal;
public get currentMode(): number {
return this._currentMode;
}
public set currentMode(value: number) {
this._currentMode = value;
}
public getModeObject(modeHandler: ModeHandler): Mode { public getModeObject(modeHandler: ModeHandler): Mode {
return modeHandler.modeList.find(mode => mode.isActive); return modeHandler.modeList.find(mode => mode.isActive);
@ -361,6 +373,7 @@ interface IViewState {
export class ModeHandler implements vscode.Disposable { export class ModeHandler implements vscode.Disposable {
public static IsTesting = false; public static IsTesting = false;
private _toBeDisposed: vscode.Disposable[] = [];
private _modes: Mode[]; private _modes: Mode[];
private static _statusBarItem: vscode.StatusBarItem; private static _statusBarItem: vscode.StatusBarItem;
private _vimState: VimState; private _vimState: VimState;
@ -443,12 +456,14 @@ export class ModeHandler implements vscode.Disposable {
} }
// Handle scenarios where mouse used to change current position. // Handle scenarios where mouse used to change current position.
vscode.window.onDidChangeTextEditorSelection((e: vscode.TextEditorSelectionChangeEvent) => { const disposer = vscode.window.onDidChangeTextEditorSelection((e: vscode.TextEditorSelectionChangeEvent) => {
taskQueue.enqueueTask({ taskQueue.enqueueTask({
promise: () => this.handleSelectionChange(e), promise: () => this.handleSelectionChange(e),
isRunning: false, isRunning: false,
}); });
}); });
this._toBeDisposed.push(disposer);
} }
private async handleSelectionChange(e: vscode.TextEditorSelectionChangeEvent): Promise<void> { private async handleSelectionChange(e: vscode.TextEditorSelectionChangeEvent): Promise<void> {
@ -578,6 +593,7 @@ export class ModeHandler implements vscode.Disposable {
async handleKeyEvent(key: string): Promise<Boolean> { async handleKeyEvent(key: string): Promise<Boolean> {
this._vimState.cursorPositionJustBeforeAnythingHappened = this._vimState.allCursors.map(x => x.stop); this._vimState.cursorPositionJustBeforeAnythingHappened = this._vimState.allCursors.map(x => x.stop);
try { try {
let handled = false; let handled = false;
@ -1438,6 +1454,8 @@ export class ModeHandler implements vscode.Disposable {
} }
dispose() { dispose() {
// do nothing for (const disposable of this._toBeDisposed) {
disposable.dispose();
}
} }
} }