mirror of
https://github.com/Microsoft/vscode
synced 2024-08-27 21:09:43 +00:00
Settings editors - fix \n enum value breaking json syntax
This commit is contained in:
parent
0dea26f6e7
commit
dae69dbf00
|
@ -1010,9 +1010,12 @@ export class SettingsRenderer implements ITreeRenderer {
|
|||
let enumDescriptionText = '';
|
||||
if (element.valueType === 'enum' && element.setting.enumDescriptions && element.setting.enum && element.setting.enum.length < SettingsRenderer.MAX_ENUM_DESCRIPTIONS) {
|
||||
enumDescriptionText = '\n' + element.setting.enumDescriptions
|
||||
.map((desc, i) => desc ?
|
||||
` - \`${element.setting.enum[i]}\`: ${desc}` :
|
||||
` - \`${element.setting.enum[i]}\``)
|
||||
.map((desc, i) => {
|
||||
const displayEnum = escapeInvisibleChars(setting.enum[i]);
|
||||
return desc ?
|
||||
` - \`${displayEnum}\`: ${desc}` :
|
||||
` - \`${setting.enum[i]}\``;
|
||||
})
|
||||
.filter(desc => !!desc)
|
||||
.join('\n');
|
||||
}
|
||||
|
|
|
@ -899,9 +899,10 @@ class SettingsContentBuilder {
|
|||
|
||||
if (setting.enumDescriptions && setting.enumDescriptions.some(desc => !!desc)) {
|
||||
setting.enumDescriptions.forEach((desc, i) => {
|
||||
const displayEnum = escapeInvisibleChars(setting.enum[i]);
|
||||
const line = desc ?
|
||||
`${setting.enum[i]}: ${fixSettingLink(desc)}` :
|
||||
setting.enum[i];
|
||||
`${displayEnum}: ${fixSettingLink(desc)}` :
|
||||
displayEnum;
|
||||
|
||||
this._contentByLines.push(` // - ${line}`);
|
||||
|
||||
|
@ -942,6 +943,12 @@ class SettingsContentBuilder {
|
|||
}
|
||||
}
|
||||
|
||||
function escapeInvisibleChars(enumValue: string): string {
|
||||
return enumValue && enumValue
|
||||
.replace(/\n/g, '\\n')
|
||||
.replace(/\r/g, '\\r');
|
||||
}
|
||||
|
||||
export function defaultKeybindingsContents(keybindingService: IKeybindingService): string {
|
||||
const defaultsHeader = '// ' + nls.localize('defaultKeybindingsHeader', "Overwrite key bindings by placing them into your key bindings file.");
|
||||
return defaultsHeader + '\n' + keybindingService.getDefaultKeybindingsContent();
|
||||
|
|
Loading…
Reference in a new issue