提交 d29788c0 编写于 作者: B Benjamin Pasero

Config to limit/disable the new Untitled tab auto-naming (fix #90378)

上级 aeda438a
......@@ -42,6 +42,19 @@ import { workbenchConfigurationNodeBase } from 'vs/workbench/common/configuratio
key: 'tabDescription'
}, "Controls the format of the label for an editor."),
},
'workbench.editor.untitled.labelFormat': {
'type': 'string',
'enum': ['content', 'name'],
'enumDescriptions': [
nls.localize('workbench.editor.untitled.labelFormat.content', "The name of the untitled file is derived from the contents of its first line with a fallback to the name in case the line is empty or contains no word characters."),
nls.localize('workbench.editor.untitled.labelFormat.name', "The name of the untitled file is not derived from the contents of the file."),
],
'default': 'content',
'description': nls.localize({
comment: ['This is the description for a setting. Values surrounded by parenthesis are not to be translated.'],
key: 'untitledLabelFormat'
}, "Controls the format of the label for an untitled editor."),
},
'workbench.editor.tabCloseButton': {
'type': 'string',
'enum': ['left', 'right', 'off'],
......
......@@ -92,7 +92,7 @@ export class UntitledTextEditorModel extends BaseTextEditorModel implements IUnt
// Take name from first line if present and only if
// we have no associated file path. In that case we
// prefer the file name as title.
if (!this.hasAssociatedFilePath && this.cachedModelFirstLineWords) {
if (this.configuredLabelFormat === 'content' && !this.hasAssociatedFilePath && this.cachedModelFirstLineWords) {
return this.cachedModelFirstLineWords;
}
......@@ -104,7 +104,9 @@ export class UntitledTextEditorModel extends BaseTextEditorModel implements IUnt
private ignoreDirtyOnModelContentChange = false;
private versionId = 0;
private configuredEncoding: string | undefined;
private configuredLabelFormat: 'content' | 'name' = 'content';
constructor(
public readonly resource: URI,
......@@ -130,25 +132,39 @@ export class UntitledTextEditorModel extends BaseTextEditorModel implements IUnt
this.setMode(preferredMode);
}
// Fetch config
this.onConfigurationChange(false);
this.registerListeners();
}
private registerListeners(): void {
// Config Changes
this._register(this.textResourceConfigurationService.onDidChangeConfiguration(e => this.onConfigurationChange()));
this._register(this.textResourceConfigurationService.onDidChangeConfiguration(e => this.onConfigurationChange(true)));
}
private onConfigurationChange(): void {
const configuredEncoding = this.textResourceConfigurationService.getValue<string>(this.resource, 'files.encoding');
private onConfigurationChange(fromEvent: boolean): void {
// Encoding
const configuredEncoding = this.textResourceConfigurationService.getValue<string>(this.resource, 'files.encoding');
if (this.configuredEncoding !== configuredEncoding) {
this.configuredEncoding = configuredEncoding;
if (!this.preferredEncoding) {
if (fromEvent && !this.preferredEncoding) {
this._onDidChangeEncoding.fire(); // do not fire event if we have a preferred encoding set
}
}
// Label Format
const configuredLabelFormat = this.textResourceConfigurationService.getValue<string>(this.resource, 'workbench.editor.untitled.labelFormat');
if (this.configuredLabelFormat !== configuredLabelFormat && (configuredLabelFormat === 'content' || configuredLabelFormat === 'name')) {
this.configuredLabelFormat = configuredLabelFormat;
if (fromEvent) {
this._onDidChangeName.fire();
}
}
}
getVersionId(): number {
......@@ -281,13 +297,10 @@ export class UntitledTextEditorModel extends BaseTextEditorModel implements IUnt
this.updateTextEditorModel(undefined, this.preferredMode);
}
// Figure out encoding now that model is present
this.configuredEncoding = this.textResourceConfigurationService.getValue<string>(this.resource, 'files.encoding');
// Listen to text model events
const textEditorModel = assertIsDefined(this.textEditorModel);
this._register(textEditorModel.onDidChangeContent(e => this.onModelContentChanged(textEditorModel, e)));
this._register(textEditorModel.onDidChangeLanguage(() => this.onConfigurationChange())); // mode change can have impact on config
this._register(textEditorModel.onDidChangeLanguage(() => this.onConfigurationChange(true))); // mode change can have impact on config
// Only adjust name and dirty state etc. if we
// actually created the untitled model
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册