reset terminal name when empty title is provided (#137589)
This commit is contained in:
parent
6add87d451
commit
fe1958cdcb
|
@ -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.
|
||||
|
|
|
@ -836,7 +836,7 @@ export function registerTerminalActions() {
|
|||
});
|
||||
}
|
||||
async run(accessor: ServicesAccessor, resource: unknown) {
|
||||
doWithInstance(accessor, resource)?.rename();
|
||||
doWithInstance(accessor, resource)?.rename('triggerQuickpick');
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -851,7 +851,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 {
|
||||
|
@ -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
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -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) {
|
||||
|
@ -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() {
|
||||
|
@ -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 || '',
|
||||
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue