提交 8162c25b 编写于 作者: P Pine Wu

Fix #78241

上级 e81b51de
......@@ -702,29 +702,27 @@ export class SettingArrayRenderer extends AbstractSettingRenderer implements ITr
? [...template.context.scopeValue]
: [...template.context.value];
// Delete value
if (e.removeIndex !== undefined) {
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);
}
// 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);
}
}
}
// 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;
}
// For some reason, we are updating and cannot find original value
// Just append the value in this case
else {
newValue.push(e.value);
}
}
if (
template.context.defaultValue &&
isArray(template.context.defaultValue) &&
......
......@@ -132,14 +132,16 @@ registerThemingParticipant((theme: ITheme, collector: ICssStyleCollector) => {
}
});
type EditKey = 'none' | 'create' | number;
export class ListSettingListModel {
private _dataItems: IListDataItem[] = [];
private _editKey: string | null;
private _editKey: EditKey;
private _selectedIdx: number | null;
get items(): IListViewItem[] {
const items = this._dataItems.map((item, i) => {
const editing = item.value === this._editKey;
const editing = typeof this._editKey === 'number' && this._editKey === i;
return <IListViewItem>{
...item,
editing,
......@@ -147,7 +149,7 @@ export class ListSettingListModel {
};
});
if (this._editKey === '') {
if (this._editKey === 'create') {
items.push({
editing: true,
selected: true,
......@@ -159,7 +161,7 @@ export class ListSettingListModel {
return items;
}
setEditKey(key: string | null): void {
setEditKey(key: EditKey): void {
this._editKey = key;
}
......@@ -196,7 +198,7 @@ export interface IListChangeEvent {
originalValue: string;
value?: string;
sibling?: string;
removeIndex?: number;
targetIndex?: number;
}
export class ListSettingWidget extends Disposable {
......@@ -295,7 +297,7 @@ export class ListSettingWidget extends Disposable {
const item = this.model.items[targetIdx];
if (item) {
this.editSetting(item.value);
this.editSetting(targetIdx);
e.preventDefault();
e.stopPropagation();
}
......@@ -349,24 +351,24 @@ export class ListSettingWidget extends Disposable {
enabled: true,
id: 'workbench.action.removeListItem',
tooltip: this.getLocalizedStrings().deleteActionTooltip,
run: () => this._onDidChangeList.fire({ originalValue: key, value: undefined, removeIndex: idx })
run: () => this._onDidChangeList.fire({ originalValue: key, value: undefined, targetIndex: idx })
};
}
private createEditAction(key: string): IAction {
private createEditAction(idx: number): IAction {
return <IAction>{
class: 'setting-listAction-edit',
enabled: true,
id: 'workbench.action.editListItem',
tooltip: this.getLocalizedStrings().editActionTooltip,
run: () => {
this.editSetting(key);
this.editSetting(idx);
}
};
}
private editSetting(key: string): void {
this.model.setEditKey(key);
private editSetting(idx: number): void {
this.model.setEditKey(idx);
this.renderList();
}
......@@ -391,7 +393,7 @@ export class ListSettingWidget extends Disposable {
siblingElement.textContent = item.sibling ? ('when: ' + item.sibling) : null;
actionBar.push([
this.createEditAction(item.value),
this.createEditAction(idx),
this.createDeleteAction(item.value, idx)
], { icon: true, label: false });
......@@ -419,7 +421,7 @@ export class ListSettingWidget extends Disposable {
this._register(attachButtonStyler(startAddButton, this.themeService));
this._register(startAddButton.onDidClick(() => {
this.model.setEditKey('');
this.model.setEditKey('create');
this.renderList();
}));
......@@ -430,14 +432,14 @@ export class ListSettingWidget extends Disposable {
const rowElement = $('.setting-list-edit-row');
const onSubmit = (edited: boolean) => {
this.model.setEditKey(null);
this.model.setEditKey('none');
const value = valueInput.value.trim();
if (edited && !isUndefinedOrNull(value)) {
this._onDidChangeList.fire({
originalValue: item.value,
value: value,
sibling: siblingInput && siblingInput.value.trim(),
removeIndex: value === '' ? idx : undefined
targetIndex: idx
});
}
this.renderList();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册