diff --git a/HISTORY.md b/HISTORY.md index cee367d..1fa2dc4 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -2,6 +2,11 @@ https://github.com/josdejong/jsoneditor +## not yet published, version 8.6.4 + +- Fix #921: `sortObjectKeys` emits `onChange` events. + + ## 2020-03-18, version 8.6.3 - Fix #932: `JSONEditor.update` broken, did not always recognize when the diff --git a/src/js/Node.js b/src/js/Node.js index e0278e6..69695f3 100644 --- a/src/js/Node.js +++ b/src/js/Node.js @@ -516,9 +516,10 @@ export class Node { } this.value = '' - // sort object keys + // sort object keys during initialization. Must not trigger an onChange action if (this.editor.options.sortObjectKeys === true) { - this.sort([], 'asc') + const triggerAction = false + this.sort([], 'asc', triggerAction) } } else { // value @@ -3201,9 +3202,12 @@ export class Node { * or 'array'. * @param {String[] | string} path Path of the child value to be compared * @param {String} direction Sorting direction. Available values: "asc", "desc" + * @param {boolean} [triggerAction=true] If true (default), a user action will be + * triggered, creating an entry in history + * and invoking onChange. * @private */ - sort (path, direction) { + sort (path, direction, triggerAction = true) { if (typeof path === 'string') { path = parsePath(path) } @@ -3249,14 +3253,16 @@ export class Node { // update the index numbering this._updateDomIndexes() - - this.editor._onAction('sort', { - path: this.getInternalPath(), - oldChilds: oldChilds, - newChilds: this.childs - }) - + this.showChilds() + + if (triggerAction === true) { + this.editor._onAction('sort', { + path: this.getInternalPath(), + oldChilds: oldChilds, + newChilds: this.childs + }) + } } /**