diff --git a/HISTORY.md b/HISTORY.md index 181bfa0..cfd733f 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -11,6 +11,7 @@ https://github.com/josdejong/jsoneditor - Implemented #183: display a checkbox left from boolean values, so you can easily switch between true/false. - Added a minimalist bundle to the `dist` folder, excluding `ace` and `ajv`. +- Fixed #222: editor throwing `onChange` events when switching mode. - Fixed an error throw when switching to mode "code" via the menu. - Fixed interfering shortcut keys: changed quick keys to select multiple fields from `Shift+Arrow Up/Down` to `Ctrl+Shift+Arrow Up/Down`. diff --git a/gulpfile.js b/gulpfile.js index 51e6e22..bfc09fa 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -58,12 +58,6 @@ var compilerMinimalist = webpack({ new webpack.IgnorePlugin(new RegExp('^brace$')), new webpack.IgnorePlugin(new RegExp('^ajv')) ], - //exclude: [ - // 'brace', - // 'ajv/dist/ajv.bundle.js' - //], - - cache: true }); diff --git a/src/js/textmode.js b/src/js/textmode.js index a4adde2..77b00aa 100644 --- a/src/js/textmode.js +++ b/src/js/textmode.js @@ -365,7 +365,13 @@ textmode.setText = function(jsonText) { this.textarea.value = text; } if (this.aceEditor) { + // prevent emitting onChange events while setting new text + var originalOnChange = this.options.onChange; + this.options.onChange = null; + this.aceEditor.setValue(text, -1); + + this.options.onChange = originalOnChange; } // validate JSON schema diff --git a/test/test_build.html b/test/test_build.html index 6016dc0..173a54d 100644 --- a/test/test_build.html +++ b/test/test_build.html @@ -46,6 +46,9 @@ onError: function (err) { alert(err.toString()); }, + onChange: function () { + console.log('change'); + }, indentation: 4, escapeUnicode: true };