提交 1558fd55 编写于 作者: D Daniel Imms

Clear up references causing dispose issues in terminal

Part of #46356
上级 8557d611
...@@ -7,7 +7,7 @@ import { IDisposable, dispose } from 'vs/base/common/lifecycle'; ...@@ -7,7 +7,7 @@ import { IDisposable, dispose } from 'vs/base/common/lifecycle';
const WIDGET_HEIGHT = 29; const WIDGET_HEIGHT = 29;
export class TerminalWidgetManager { export class TerminalWidgetManager implements IDisposable {
private _container: HTMLElement; private _container: HTMLElement;
private _xtermViewport: HTMLElement; private _xtermViewport: HTMLElement;
...@@ -24,6 +24,14 @@ export class TerminalWidgetManager { ...@@ -24,6 +24,14 @@ export class TerminalWidgetManager {
this._initTerminalHeightWatcher(terminalWrapper); this._initTerminalHeightWatcher(terminalWrapper);
} }
public dispose(): void {
if (this._container) {
this._container.parentElement.removeChild(this._container);
this._container = null;
}
this._xtermViewport = null;
}
private _initTerminalHeightWatcher(terminalWrapper: HTMLElement) { private _initTerminalHeightWatcher(terminalWrapper: HTMLElement) {
// Watch the xterm.js viewport for style changes and do a layout if it changes // Watch the xterm.js viewport for style changes and do a layout if it changes
this._xtermViewport = <HTMLElement>terminalWrapper.querySelector('.xterm-viewport'); this._xtermViewport = <HTMLElement>terminalWrapper.querySelector('.xterm-viewport');
......
...@@ -71,9 +71,10 @@ export class KillTerminalAction extends Action { ...@@ -71,9 +71,10 @@ export class KillTerminalAction extends Action {
} }
public run(event?: any): TPromise<any> { public run(event?: any): TPromise<any> {
const terminalInstance = this.terminalService.getActiveInstance(); console.log('kill');
if (terminalInstance) { const instance = this.terminalService.getActiveInstance();
this.terminalService.getActiveInstance().dispose(); if (instance) {
instance.dispose();
if (this.terminalService.terminalInstances.length > 0) { if (this.terminalService.terminalInstances.length > 0) {
this.terminalService.showPanel(true); this.terminalService.showPanel(true);
} }
......
...@@ -155,14 +155,14 @@ export class TerminalInstance implements ITerminalInstance { ...@@ -155,14 +155,14 @@ export class TerminalInstance implements ITerminalInstance {
} }
}); });
this._configurationService.onDidChangeConfiguration(e => { this.addDisposable(this._configurationService.onDidChangeConfiguration(e => {
if (e.affectsConfiguration('terminal.integrated')) { if (e.affectsConfiguration('terminal.integrated')) {
this.updateConfig(); this.updateConfig();
} }
if (e.affectsConfiguration('editor.accessibilitySupport')) { if (e.affectsConfiguration('editor.accessibilitySupport')) {
this.updateAccessibilitySupport(); this.updateAccessibilitySupport();
} }
}); }));
} }
public addDisposable(disposable: lifecycle.IDisposable): void { public addDisposable(disposable: lifecycle.IDisposable): void {
...@@ -558,18 +558,21 @@ export class TerminalInstance implements ITerminalInstance { ...@@ -558,18 +558,21 @@ export class TerminalInstance implements ITerminalInstance {
public dispose(): void { public dispose(): void {
this._logService.trace(`terminalInstance#dispose (id: ${this.id})`); this._logService.trace(`terminalInstance#dispose (id: ${this.id})`);
if (this._windowsShellHelper) { this._windowsShellHelper = lifecycle.dispose(this._windowsShellHelper);
this._windowsShellHelper.dispose(); this._linkHandler = lifecycle.dispose(this._linkHandler);
} this._commandTracker = lifecycle.dispose(this._commandTracker);
if (this._linkHandler) { this._widgetManager = lifecycle.dispose(this._widgetManager);
this._linkHandler.dispose();
}
if (this._xterm && this._xterm.element) { if (this._xterm && this._xterm.element) {
this._hadFocusOnExit = dom.hasClass(this._xterm.element, 'focus'); this._hadFocusOnExit = dom.hasClass(this._xterm.element, 'focus');
} }
if (this._wrapperElement) { if (this._wrapperElement) {
if ((<any>this._wrapperElement).xterm) {
(<any>this._wrapperElement).xterm = null;
}
this._container.removeChild(this._wrapperElement); this._container.removeChild(this._wrapperElement);
this._wrapperElement = null; this._wrapperElement = null;
this._xtermElement = null;
} }
if (this._xterm) { if (this._xterm) {
const buffer = (<any>this._xterm.buffer); const buffer = (<any>this._xterm.buffer);
...@@ -577,9 +580,7 @@ export class TerminalInstance implements ITerminalInstance { ...@@ -577,9 +580,7 @@ export class TerminalInstance implements ITerminalInstance {
this._xterm.dispose(); this._xterm.dispose();
this._xterm = null; this._xterm = null;
} }
if (this._processManager) { this._processManager = lifecycle.dispose(this._processManager);
this._processManager.dispose();
}
if (!this._isDisposed) { if (!this._isDisposed) {
this._isDisposed = true; this._isDisposed = true;
this._onDisposed.fire(this); this._onDisposed.fire(this);
......
...@@ -121,6 +121,7 @@ export class TerminalLinkHandler { ...@@ -121,6 +121,7 @@ export class TerminalLinkHandler {
} }
public dispose(): void { public dispose(): void {
this._xterm = null;
this._hoverDisposables = dispose(this._hoverDisposables); this._hoverDisposables = dispose(this._hoverDisposables);
this._mouseMoveDisposable = dispose(this._mouseMoveDisposable); this._mouseMoveDisposable = dispose(this._mouseMoveDisposable);
} }
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
import { Terminal, IMarker } from 'vscode-xterm'; import { Terminal, IMarker } from 'vscode-xterm';
import { ITerminalCommandTracker } from 'vs/workbench/parts/terminal/common/terminal'; import { ITerminalCommandTracker } from 'vs/workbench/parts/terminal/common/terminal';
import { IDisposable } from 'vs/base/common/lifecycle';
/** /**
* The minimize size of the prompt in which to assume the line is a command. * The minimize size of the prompt in which to assume the line is a command.
...@@ -21,7 +22,7 @@ export enum ScrollPosition { ...@@ -21,7 +22,7 @@ export enum ScrollPosition {
Middle Middle
} }
export class TerminalCommandTracker implements ITerminalCommandTracker { export class TerminalCommandTracker implements ITerminalCommandTracker, IDisposable {
private _currentMarker: IMarker | Boundary = Boundary.Bottom; private _currentMarker: IMarker | Boundary = Boundary.Bottom;
private _selectionStart: IMarker | Boundary | null = null; private _selectionStart: IMarker | Boundary | null = null;
private _isDisposable: boolean = false; private _isDisposable: boolean = false;
...@@ -32,6 +33,10 @@ export class TerminalCommandTracker implements ITerminalCommandTracker { ...@@ -32,6 +33,10 @@ export class TerminalCommandTracker implements ITerminalCommandTracker {
this._xterm.on('key', key => this._onKey(key)); this._xterm.on('key', key => this._onKey(key));
} }
public dispose(): void {
this._xterm = null;
}
private _onKey(key: string): void { private _onKey(key: string): void {
if (key === '\x0d') { if (key === '\x0d') {
this._onEnter(); this._onEnter();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册