提交 29c4e311 编写于 作者: B Benjamin Pasero

window title: convert variable format from $() to ${}

上级 fcfa0c3a
......@@ -36,13 +36,13 @@ export class WindowTitleContribution implements JSONWorkerContribution {
if (this.isSettingsFile(resource) && location.length === 1 && location[0] === 'window.title') {
return Promise.resolve([
MarkedString.fromPlainText(localize('windowTitle.description', "Controls the window title based on the active editor. Variables are substituted based on the context:")),
MarkedString.fromPlainText(localize('windowTitle.activeEditorName', "$(activeEditorName): e.g. myFile.txt")),
MarkedString.fromPlainText(localize('windowTitle.activeFilePath', "$(activeFilePath): e.g. /Users/Development/myProject/myFile.txt")),
MarkedString.fromPlainText(localize('windowTitle.rootName', "$(rootName): e.g. myProject")),
MarkedString.fromPlainText(localize('windowTitle.rootPath', "$(rootPath): e.g. /Users/Development/myProject")),
MarkedString.fromPlainText(localize('windowTitle.appName', "$(appName): e.g. VS Code")),
MarkedString.fromPlainText(localize('windowTitle.dirty', "$(dirty): a dirty indicator if the active editor is dirty")),
MarkedString.fromPlainText(localize('windowTitle.separator', "$(separator): a conditional separator (\" - \") that only shows when surrounded by variables with values"))
MarkedString.fromPlainText(localize('windowTitle.activeEditorName', "${activeEditorName}: e.g. myFile.txt")),
MarkedString.fromPlainText(localize('windowTitle.activeFilePath', "${activeFilePath}: e.g. /Users/Development/myProject/myFile.txt")),
MarkedString.fromPlainText(localize('windowTitle.rootName', "${rootName}: e.g. myProject")),
MarkedString.fromPlainText(localize('windowTitle.rootPath', "${rootPath}: e.g. /Users/Development/myProject")),
MarkedString.fromPlainText(localize('windowTitle.appName', "${appName}: e.g. VS Code")),
MarkedString.fromPlainText(localize('windowTitle.dirty', "${dirty}: a dirty indicator if the active editor is dirty")),
MarkedString.fromPlainText(localize('windowTitle.separator', "${separator}: a conditional separator (\" - \") that only shows when surrounded by variables with values"))
]);
}
......
......@@ -167,7 +167,7 @@ export function template(template: string, values: { [key: string]: string | ISe
char = template[i];
// Beginning of variable
if (char === '$' || (inVariable && char === '(')) {
if (char === '$' || (inVariable && char === '{')) {
if (curVal) {
segments.push({ value: curVal, type: Type.TEXT });
}
......@@ -177,7 +177,7 @@ export function template(template: string, values: { [key: string]: string | ISe
}
// End of variable
else if (char === ')' && inVariable) {
else if (char === '}' && inVariable) {
const resolved = values[curVal];
// Variable
......
......@@ -103,26 +103,26 @@ suite('Labels', () => {
// simple
assert.strictEqual(labels.template('Foo Bar'), 'Foo Bar');
assert.strictEqual(labels.template('Foo$()Bar'), 'FooBar');
assert.strictEqual(labels.template('Foo${}Bar'), 'FooBar');
assert.strictEqual(labels.template('$FooBar'), '');
assert.strictEqual(labels.template(')FooBar'), ')FooBar');
assert.strictEqual(labels.template('Foo $(one) Bar', { one: 'value' }), 'Foo value Bar');
assert.strictEqual(labels.template('Foo $(one) Bar $(two)', { one: 'value', two: 'other value' }), 'Foo value Bar other value');
assert.strictEqual(labels.template('}FooBar'), '}FooBar');
assert.strictEqual(labels.template('Foo ${one} Bar', { one: 'value' }), 'Foo value Bar');
assert.strictEqual(labels.template('Foo ${one} Bar ${two}', { one: 'value', two: 'other value' }), 'Foo value Bar other value');
// conditional separator
assert.strictEqual(labels.template('Foo$(separator)Bar'), 'FooBar');
assert.strictEqual(labels.template('Foo$(separator)Bar', { separator: { label: ' - ' } }), 'FooBar');
assert.strictEqual(labels.template('$(separator)Foo$(separator)Bar', { value: 'something', separator: { label: ' - ' } }), 'FooBar');
assert.strictEqual(labels.template('$(value) Foo$(separator)Bar', { value: 'something', separator: { label: ' - ' } }), 'something FooBar');
assert.strictEqual(labels.template('Foo${separator}Bar'), 'FooBar');
assert.strictEqual(labels.template('Foo${separator}Bar', { separator: { label: ' - ' } }), 'FooBar');
assert.strictEqual(labels.template('${separator}Foo${separator}Bar', { value: 'something', separator: { label: ' - ' } }), 'FooBar');
assert.strictEqual(labels.template('${value} Foo${separator}Bar', { value: 'something', separator: { label: ' - ' } }), 'something FooBar');
// // real world example (macOS)
let t = '$(activeEditorName)$(separator)$(rootName)';
let t = '${activeEditorName}${separator}${rootName}';
assert.strictEqual(labels.template(t, { activeEditorName: '', rootName: '', separator: { label: ' - ' } }), '');
assert.strictEqual(labels.template(t, { activeEditorName: '', rootName: 'root', separator: { label: ' - ' } }), 'root');
assert.strictEqual(labels.template(t, { activeEditorName: 'markdown.txt', rootName: 'root', separator: { label: ' - ' } }), 'markdown.txt - root');
// // real world example (other)
t = '$(dirty)$(activeEditorName)$(separator)$(rootName)$(separator)$(appName)';
t = '${dirty}${activeEditorName}${separator}${rootName}${separator}${appName}';
assert.strictEqual(labels.template(t, { dirty: '', activeEditorName: '', rootName: '', appName: '', separator: { label: ' - ' } }), '');
assert.strictEqual(labels.template(t, { dirty: '', activeEditorName: '', rootName: '', appName: 'Visual Studio Code', separator: { label: ' - ' } }), 'Visual Studio Code');
assert.strictEqual(labels.template(t, { dirty: '', activeEditorName: '', rootName: 'monaco', appName: 'Visual Studio Code', separator: { label: ' - ' } }), 'monaco - Visual Studio Code');
......
......@@ -236,16 +236,16 @@ Note that there can still be cases where this setting is ignored (e.g. when usin
},
'window.title': {
'type': 'string',
'default': isMacintosh ? '$(activeEditorName)$(separator)$(rootName)' : '$(dirty)$(activeEditorName)$(separator)$(rootName)$(separator)$(appName)',
'default': isMacintosh ? '${activeEditorName}${separator}${rootName}' : '${dirty}${activeEditorName}${separator}${rootName}${separator}${appName}',
'description': nls.localize('title',
`Controls the window title based on the active editor. Variables are substituted based on the context:
$(activeEditorName): e.g. myFile.txt
$(activeFilePath): e.g. /Users/Development/myProject/myFile.txt
$(rootName): e.g. myProject
$(rootPath): e.g. /Users/Development/myProject
$(appName): e.g. VS Code
$(dirty): a dirty indicator if the active editor is dirty
$(separator): a conditional separator (" - ") that only shows when surrounded by variables with values`)
\${activeEditorName}: e.g. myFile.txt
\${activeFilePath}: e.g. /Users/Development/myProject/myFile.txt
\${rootName}: e.g. myProject
\${rootPath}: e.g. /Users/Development/myProject
\${appName}: e.g. VS Code
\${dirty}: a dirty indicator if the active editor is dirty
\${separator}: a conditional separator (" - ") that only shows when surrounded by variables with values`)
},
'window.newWindowDimensions': {
'type': 'string',
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册