提交 1e300c41 编写于 作者: R Rob Lourens

Settings Editor - fix multiword category label cases

上级 34735bc7
......@@ -48,7 +48,7 @@ export const tocData: ITOCEntry = {
settings: ['editor.format*']
},
{
id: 'editor/diff',
id: 'editor/diffEditor',
label: 'Diff Editor',
settings: ['diffEditor.*']
},
......
......@@ -288,13 +288,7 @@ export class SettingsDataSource implements IDataSource {
}
export function settingKeyToDisplayFormat(key: string, groupId = ''): { category: string, label: string } {
groupId = groupId.replace(/\//g, '.');
let label = key
.replace(/\.([a-z])/g, (match, p1) => `.${p1.toUpperCase()}`)
.replace(/([a-z])([A-Z])/g, '$1 $2') // fooBar => foo Bar
.replace(/^[a-z]/g, match => match.toUpperCase()); // foo => Foo
let label = wordifyKey(key);
const lastDotIdx = label.lastIndexOf('.');
let category = '';
if (lastDotIdx >= 0) {
......@@ -302,12 +296,22 @@ export function settingKeyToDisplayFormat(key: string, groupId = ''): { category
label = label.substr(lastDotIdx + 1);
}
groupId = wordifyKey(groupId.replace(/\//g, '.'));
category = trimCategoryForGroup(category, groupId);
return { category, label };
}
function wordifyKey(key: string): string {
return key
.replace(/\.([a-z])/g, (match, p1) => `.${p1.toUpperCase()}`)
.replace(/([a-z])([A-Z])/g, '$1 $2') // fooBar => foo Bar
.replace(/^[a-z]/g, match => match.toUpperCase()); // foo => Foo
}
function trimCategoryForGroup(category: string, groupId: string): string {
// const categoryWithoutSpaces = category.replace(/ /g, '');
const doTrim = forward => {
const parts = groupId.split('.');
while (parts.length) {
......@@ -316,6 +320,10 @@ function trimCategoryForGroup(category: string, groupId: string): string {
return category.replace(reg, '');
}
// if (reg.test(categoryWithoutSpaces)) {
// return categoryWithoutSpaces.replace(reg, '');
// }
if (forward) {
parts.pop();
} else {
......
......@@ -81,5 +81,20 @@ suite('SettingsTree', () => {
category: '',
label: 'Etc'
});
assert.deepEqual(
settingKeyToDisplayFormat('fooBar.etc', 'fooBar'),
{
category: '',
label: 'Etc'
});
assert.deepEqual(
settingKeyToDisplayFormat('fooBar.somethingElse.etc', 'fooBar'),
{
category: 'Something Else',
label: 'Etc'
});
});
});
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册