Fixed #730: in `code` mode, there was an initial undo action which clears the content

This commit is contained in:
jos 2019-07-10 14:27:46 +02:00
parent df386b6f1b
commit bc0e99ab4a
2 changed files with 27 additions and 5 deletions

View File

@ -3,6 +3,12 @@
https://github.com/josdejong/jsoneditor
## not yet published, version 6.1.1
- Fixed #730: in `code` mode, there was an initial undo action which clears
the content.
## 2019-06-22, version 6.1.0
- Implemented menu options `sort` and `transform` for modes `code` and `text`.

View File

@ -734,10 +734,12 @@ textmode.getText = function() {
};
/**
* Set the text contents of the editor
* Set the text contents of the editor and optionally clear the history
* @param {String} jsonText
* @param {boolean} clearHistory Only applicable for mode 'code'
* @private
*/
textmode.setText = function(jsonText) {
textmode._setText = function(jsonText, clearHistory) {
var text;
if (this.options.escapeUnicode === true) {
@ -756,12 +758,28 @@ textmode.setText = function(jsonText) {
this.aceEditor.setValue(text, -1);
if (clearHistory) {
// prevent initial undo action clearing the initial contents
var me = this;
setTimeout(function () {
me.aceEditor.session.getUndoManager().reset();
}, 0);
}
this.onChangeDisabled = false;
}
// validate JSON schema
this._debouncedValidate();
};
/**
* Set the text contents of the editor
* @param {String} jsonText
*/
textmode.setText = function(jsonText) {
this._setText(jsonText, true)
};
/**
* Update the text contents
* @param {string} jsonText
@ -772,9 +790,7 @@ textmode.updateText = function(jsonText) {
return;
}
this.onChangeDisabled = true; // don't fire an onChange event
this.setText(jsonText);
this.onChangeDisabled = false;
this._setText(jsonText, false);
};
/**