diff --git a/src/state/editors.ts b/src/state/editors.ts index c0f1870..aa54a26 100644 --- a/src/state/editors.ts +++ b/src/state/editors.ts @@ -687,7 +687,7 @@ export class Editors implements vscode.Disposable { state.dispose(); } - this._lastRemovedEditorStates.length === 0; + this._lastRemovedEditorStates.length = 0; // Dispose of fallback editor, if any. const fallback = this._fallbacks.get(document); diff --git a/src/state/extension.ts b/src/state/extension.ts index c98ceba..f579b4a 100644 --- a/src/state/extension.ts +++ b/src/state/extension.ts @@ -204,7 +204,6 @@ export class Extension implements vscode.Disposable { }, true, ); - } /** @@ -219,6 +218,24 @@ export class Extension implements vscode.Disposable { assert(this._autoDisposables.size === 0); this.statusBar.dispose(); + + // Clear configuration handlers. + this._configurationChangeHandlers.clear(); + + // Dispose of all subscriptions. + for (const subscription of this._subscriptions) { + subscription.dispose(); + } + this._subscriptions.length = 0; + + // Dispose of core components. + this.editors.dispose(); + this.recorder.dispose(); + this.modes.dispose(); + this.registers.dispose(); + + // Dismiss error message, if any. + this.dismissErrorMessage(); } /** diff --git a/src/state/modes.ts b/src/state/modes.ts index 27d42af..09b9aaf 100644 --- a/src/state/modes.ts +++ b/src/state/modes.ts @@ -552,7 +552,7 @@ export declare namespace Mode { /** * The set of all modes. */ -export class Modes implements Iterable { +export class Modes implements Iterable, vscode.Disposable { private readonly _vscodeModeDefaults: Mode.Configuration = { cursorStyle: "line", inheritFrom: null, @@ -581,6 +581,13 @@ export class Modes implements Iterable { this._observePreferences(extension); } + public dispose(): void { + for (const mode of this._modes.values()) { + mode.dispose(); + } + this._modes.clear(); + } + /** * The default mode configured using `dance.defaultMode`. */ diff --git a/src/state/recorder.ts b/src/state/recorder.ts index 3e6bcf9..f8fe6f0 100644 --- a/src/state/recorder.ts +++ b/src/state/recorder.ts @@ -204,7 +204,11 @@ export class Recorder implements vscode.Disposable { * call. */ public cursorFromEnd() { - return new Cursor(this, this._previousBuffers.length, this._buffer.length - 1); + return new Cursor( + this, + this._previousBuffers.length, + this._buffer.length === 0 ? 0 : this._buffer.length - 1, + ); } /**