Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reset terminal name when empty title is provided #137589

Merged
merged 2 commits into from
Nov 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/vs/workbench/contrib/terminal/browser/terminal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -768,9 +768,10 @@ export interface ITerminalInstance {

/**
* Sets the terminal name to the provided title or triggers a quick pick
* to take user input.
* to take user input. If no title is provided, will reset based to the value indicated
* user's configration.
*/
rename(title?: string): Promise<void>;
rename(title?: string | 'triggerQuickpick'): Promise<void>;

/**
* Triggers a quick pick to change the icon of this terminal.
Expand Down
8 changes: 4 additions & 4 deletions src/vs/workbench/contrib/terminal/browser/terminalActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -837,7 +837,7 @@ export function registerTerminalActions() {
});
}
async run(accessor: ServicesAccessor, resource: unknown) {
doWithInstance(accessor, resource)?.rename();
doWithInstance(accessor, resource)?.rename('triggerQuickpick');
}
});

Expand All @@ -852,7 +852,7 @@ export function registerTerminalActions() {
});
}
async run(accessor: ServicesAccessor) {
return accessor.get(ITerminalGroupService).activeInstance?.rename();
return accessor.get(ITerminalGroupService).activeInstance?.rename('triggerQuickpick');
}
});
registerAction2(class extends Action2 {
Expand Down Expand Up @@ -2132,8 +2132,8 @@ function focusNext(accessor: ServicesAccessor): void {
export function validateTerminalName(name: string): { content: string, severity: Severity } | null {
if (!name || name.trim().length === 0) {
return {
content: localize('emptyTerminalNameError', "A name must be provided."),
severity: Severity.Error
content: localize('emptyTerminalNameInfo', "Providing no name will reset it to the default value"),
severity: Severity.Info
};
}

Expand Down
22 changes: 11 additions & 11 deletions src/vs/workbench/contrib/terminal/browser/terminalInstance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1466,10 +1466,11 @@ export class TerminalInstance extends Disposable implements ITerminalInstance {
}

refreshTabLabels(title: string | undefined, eventSource: TitleEventSource): void {
const reset = !title;
title = this._updateTitleProperties(title, eventSource);
const titleChanged = title !== this._title;
this._title = title;
this._labelComputer?.refreshLabel();
this._labelComputer?.refreshLabel(reset);
this._setAriaLabel(this.xterm?.raw, this._instanceId, this._title);

if (this._titleReadyComplete) {
Expand Down Expand Up @@ -1762,16 +1763,14 @@ export class TerminalInstance extends Disposable implements ITerminalInstance {
return this._linkManager.registerExternalLinkProvider(this, provider);
}

async rename(title?: string) {
if (!title) {
async rename(title?: string | 'triggerQuickpick') {
if (title === 'triggerQuickpick') {
title = await this._quickInputService.input({
value: this.title,
prompt: nls.localize('workbench.action.terminal.rename.prompt', "Enter terminal name"),
});
}
if (title) {
this.refreshTabLabels(title, TitleEventSource.Api);
}
this.refreshTabLabels(title, TitleEventSource.Api);
}

async changeIcon() {
Expand Down Expand Up @@ -2039,17 +2038,18 @@ export class TerminalLabelComputer extends Disposable {
super();
}

refreshLabel(): void {
this._title = this.computeLabel(this._configHelper.config.tabs.title, TerminalLabelType.Title);
refreshLabel(reset?: boolean): void {
this._title = this.computeLabel(this._configHelper.config.tabs.title, TerminalLabelType.Title, reset);
this._description = this.computeLabel(this._configHelper.config.tabs.description, TerminalLabelType.Description);
if (this._title !== this._instance.title || this._description !== this._instance.description) {
if (this._title !== this._instance.title || this._description !== this._instance.description || reset) {
this._onDidChangeLabel.fire({ title: this._title, description: this._description });
}
}

computeLabel(
labelTemplate: string,
labelType: TerminalLabelType
labelType: TerminalLabelType,
reset?: boolean
) {
const templateProperties: ITerminalLabelTemplateProperties = {
cwd: this._instance.cwd || this._instance.initialCwd || '',
Expand All @@ -2068,7 +2068,7 @@ export class TerminalLabelComputer extends Disposable {
if (!labelTemplate) {
return labelType === TerminalLabelType.Title ? (this._instance.processName || '') : '';
}
if (this._instance.staticTitle && labelType === TerminalLabelType.Title) {
if (!reset && this._instance.staticTitle && labelType === TerminalLabelType.Title) {
return this._instance.staticTitle.replace(/[\n\r\t]/g, '') || templateProperties.process?.replace(/[\n\r\t]/g, '') || '';
}
const detection = this._instance.capabilities.includes(ProcessCapability.CwdDetection);
Expand Down