diff --git a/src/vs/workbench/parts/terminal/electron-browser/terminalActions.ts b/src/vs/workbench/parts/terminal/electron-browser/terminalActions.ts index 1c7a798b747..6ead524b144 100644 --- a/src/vs/workbench/parts/terminal/electron-browser/terminalActions.ts +++ b/src/vs/workbench/parts/terminal/electron-browser/terminalActions.ts @@ -581,6 +581,5 @@ export class RenameTerminalAction extends Action { terminalInstance.setTitle(name); } }); - } } diff --git a/src/vs/workbench/parts/terminal/electron-browser/terminalInstance.ts b/src/vs/workbench/parts/terminal/electron-browser/terminalInstance.ts index 2909a276483..abf9d69364d 100644 --- a/src/vs/workbench/parts/terminal/electron-browser/terminalInstance.ts +++ b/src/vs/workbench/parts/terminal/electron-browser/terminalInstance.ts @@ -62,7 +62,6 @@ export class TerminalInstance implements ITerminalInstance { private _isDisposed: boolean; private _onDisposed: Emitter; private _onDataForApi: Emitter<{ instance: ITerminalInstance, data: string }>; - private _onMessageTitleCheck: (message: any) => void; private _onProcessIdReady: Emitter; private _onTitleChanged: Emitter; private _process: cp.ChildProcess; @@ -77,6 +76,7 @@ export class TerminalInstance implements ITerminalInstance { private _terminalHasTextContextKey: IContextKey; private _cols: number; private _rows: number; + private _messageTitleListener: (message: { type: string, content: string }) => void; private _widgetManager: TerminalWidgetManager; private _linkHandler: TerminalLinkHandler; @@ -495,13 +495,13 @@ export class TerminalInstance implements ITerminalInstance { }); if (!shell.name) { // Only listen for process title changes when a name is not provided - this._onMessageTitleCheck = (message) => { + this._messageTitleListener = (message) => { if (message.type === 'title') { this._title = message.content ? message.content : ''; this._onTitleChanged.fire(this._title); } }; - this._process.on('message', this._onMessageTitleCheck); + this._process.on('message', this._messageTitleListener); } this._process.on('message', (message) => { if (message.type === 'pid') { @@ -782,15 +782,16 @@ export class TerminalInstance implements ITerminalInstance { } public setTitle(title: string): void { - const oldTitle = this._title; - if (title !== oldTitle) { - this._title = title; + const didTitleChange = title !== this._title; + if (didTitleChange) { this._onTitleChanged.fire(title); } - // if the title is set via API, unregister the handler that automatically updates the terminal name - if (this._process) { - this._process.removeListener('message', this._onMessageTitleCheck); + // If the title was not set by the API, unregister the handler that + // automatically updates the terminal name + if (this._process && this._messageTitleListener) { + this._process.removeListener('message', this._messageTitleListener); + this._messageTitleListener = null; } } }