Revert reckoning with the order of object properties when updating an object. See #917
This commit is contained in:
parent
d62d2e14db
commit
78ac97c001
|
@ -6,6 +6,8 @@ https://github.com/josdejong/jsoneditor
|
||||||
|
|
||||||
- Fix #921: `sortObjectKeys` emits `onChange` events.
|
- Fix #921: `sortObjectKeys` emits `onChange` events.
|
||||||
- Fix #946: `language` not working in modes `text`, `code`, and `preview`.
|
- Fix #946: `language` not working in modes `text`, `code`, and `preview`.
|
||||||
|
- Revert reckoning with the order of object properties when updating an
|
||||||
|
object (introduced in `v8.6.2`). See #917.
|
||||||
- Implement support for repairing line separate JSON.
|
- Implement support for repairing line separate JSON.
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -483,32 +483,19 @@ export class Node {
|
||||||
if (hasOwnProperty(value, childField)) {
|
if (hasOwnProperty(value, childField)) {
|
||||||
childValue = value[childField]
|
childValue = value[childField]
|
||||||
if (childValue !== undefined && !(childValue instanceof Function)) {
|
if (childValue !== undefined && !(childValue instanceof Function)) {
|
||||||
const childIndex = this.childs.findIndex(child => child.field === childField)
|
const child = this.findChildByProperty(childField)
|
||||||
child = this.childs[childIndex]
|
|
||||||
|
|
||||||
if (child) {
|
if (child) {
|
||||||
// reuse existing child, keep its state
|
// reuse existing child, keep its state
|
||||||
child.setField(childField, true)
|
child.setField(childField, true)
|
||||||
child.setValue(childValue)
|
child.setValue(childValue)
|
||||||
|
|
||||||
// change the index of the property such that it matches the index of the updated JSON
|
|
||||||
if (childIndex !== i) {
|
|
||||||
this.moveBefore(child, this.childs[i], updateDom)
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
// create a new child
|
// create a new child, append to the end
|
||||||
child = new Node(this.editor, {
|
const newChild = new Node(this.editor, {
|
||||||
field: childField,
|
field: childField,
|
||||||
value: childValue
|
value: childValue
|
||||||
})
|
})
|
||||||
|
const visible = i < this.getMaxVisibleChilds()
|
||||||
const beforeNode = this.childs[i]
|
this.appendChild(newChild, visible, updateDom)
|
||||||
if (beforeNode) {
|
|
||||||
this.insertBefore(child, this.childs[i], updateDom)
|
|
||||||
} else {
|
|
||||||
const visible = i < this.getMaxVisibleChilds()
|
|
||||||
this.appendChild(child, visible, updateDom)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
i++
|
i++
|
||||||
|
|
Loading…
Reference in New Issue