Merge pull request #230392 from microsoft/tyriar/230246

Don't instantiate addons if terminal is disposed
This commit is contained in:
Daniel Imms
2024-10-03 06:17:46 -07:00
committed by GitHub
2 changed files with 12 additions and 1 deletions
@@ -914,7 +914,12 @@ export class TerminalInstance extends Disposable implements ITerminalInstance {
this.xterm?.refresh();
setTimeout(() => this._initDragAndDrop(container));
setTimeout(() => {
if (this._store.isDisposed) {
return;
}
this._initDragAndDrop(container);
}, 0);
}
/**
@@ -266,6 +266,9 @@ export class XtermTerminal extends Disposable implements IXtermTerminal, IDetach
this._shellIntegrationAddon = new ShellIntegrationAddon(options.shellIntegrationNonce ?? '', options.disableShellIntegrationReporting, this._telemetryService, this._logService);
this.raw.loadAddon(this._shellIntegrationAddon);
this._xtermAddonLoader.importAddon('clipboard').then(ClipboardAddon => {
if (this._store.isDisposed) {
return;
}
this._clipboardAddon = this._instantiationService.createInstance(ClipboardAddon, undefined, {
async readText(type: ClipboardSelectionType): Promise<string> {
return _clipboardService.readText(type === 'p' ? 'selection' : 'clipboard');
@@ -470,6 +473,9 @@ export class XtermTerminal extends Disposable implements IXtermTerminal, IDetach
private _getSearchAddon(): Promise<SearchAddonType> {
if (!this._searchAddonPromise) {
this._searchAddonPromise = this._xtermAddonLoader.importAddon('search').then((AddonCtor) => {
if (this._store.isDisposed) {
return Promise.reject('Could not create search addon, terminal is disposed');
}
this._searchAddon = new AddonCtor({ highlightLimit: XtermTerminalConstants.SearchHighlightLimit });
this.raw.loadAddon(this._searchAddon);
this._searchAddon.onDidChangeResults((results: { resultIndex: number; resultCount: number }) => {