Merge from vscode 709a07d51919d3266ca71699c6ddfb2d3547c0e1 (#6575)

This commit is contained in:
Chris LaFreniere
2019-08-02 21:06:44 -07:00
committed by GitHub
parent 402b50c03b
commit 62d2fb534d
103 changed files with 726 additions and 374 deletions

View File

@@ -698,32 +698,46 @@ export class SettingArrayRenderer extends AbstractSettingRenderer implements ITr
private onDidChangeList(template: ISettingListItemTemplate, e: IListChangeEvent): void {
if (template.context) {
const newValue: any[] | undefined = isArray(template.context.scopeValue)
? [...template.context.scopeValue]
: [...template.context.value];
let newValue: any[] = [];
if (isArray(template.context.scopeValue)) {
newValue = [...template.context.scopeValue];
} else if (isArray(template.context.value)) {
newValue = [...template.context.value];
}
// Delete value
if (e.removeIndex) {
if (!e.value && e.originalValue && e.removeIndex > -1) {
newValue.splice(e.removeIndex, 1);
if (e.targetIndex !== undefined) {
// Delete value
if (!e.value && e.originalValue && e.targetIndex > -1) {
newValue.splice(e.targetIndex, 1);
}
}
// Add value
else if (e.value && !e.originalValue) {
newValue.push(e.value);
}
// Update value
else if (e.value && e.originalValue) {
const valueIndex = newValue.indexOf(e.originalValue);
if (valueIndex > -1) {
newValue[valueIndex] = e.value;
// Update value
else if (e.value && e.originalValue) {
if (e.targetIndex > -1) {
newValue[e.targetIndex] = e.value;
}
// For some reason, we are updating and cannot find original value
// Just append the value in this case
else {
newValue.push(e.value);
}
}
// For some reason, we are updating and cannot find original value
// Just append the value in this case
else {
// Add value
else if (e.value && !e.originalValue && e.targetIndex >= newValue.length) {
newValue.push(e.value);
}
}
if (
template.context.defaultValue &&
isArray(template.context.defaultValue) &&
template.context.defaultValue.length === newValue.length &&
template.context.defaultValue.join() === newValue.join()
) {
return this._onDidChangeSetting.fire({
key: template.context.setting.key,
value: undefined, // reset setting
type: template.context.valueType
});
}
this._onDidChangeSetting.fire({
key: template.context.setting.key,