From 78ac97c001ad0bbe4d23409169b0f75d28734d3f Mon Sep 17 00:00:00 2001 From: jos Date: Sun, 29 Mar 2020 12:15:36 +0200 Subject: [PATCH] Revert reckoning with the order of object properties when updating an object. See #917 --- HISTORY.md | 2 ++ src/js/Node.js | 23 +++++------------------ 2 files changed, 7 insertions(+), 18 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index f655792..3e43986 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -6,6 +6,8 @@ https://github.com/josdejong/jsoneditor - Fix #921: `sortObjectKeys` emits `onChange` events. - 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. diff --git a/src/js/Node.js b/src/js/Node.js index 44fba88..65b9730 100644 --- a/src/js/Node.js +++ b/src/js/Node.js @@ -483,32 +483,19 @@ export class Node { if (hasOwnProperty(value, childField)) { childValue = value[childField] if (childValue !== undefined && !(childValue instanceof Function)) { - const childIndex = this.childs.findIndex(child => child.field === childField) - child = this.childs[childIndex] - + const child = this.findChildByProperty(childField) if (child) { // reuse existing child, keep its state child.setField(childField, true) 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 { - // create a new child - child = new Node(this.editor, { + // create a new child, append to the end + const newChild = new Node(this.editor, { field: childField, value: childValue }) - - const beforeNode = this.childs[i] - if (beforeNode) { - this.insertBefore(child, this.childs[i], updateDom) - } else { - const visible = i < this.getMaxVisibleChilds() - this.appendChild(child, visible, updateDom) - } + const visible = i < this.getMaxVisibleChilds() + this.appendChild(newChild, visible, updateDom) } } i++