Parse directly after setText

This commit is contained in:
jos 2019-07-24 15:19:45 +02:00
parent 72455e3302
commit 2b6caba3df
3 changed files with 14 additions and 15 deletions

View File

@ -2,16 +2,16 @@
https://github.com/josdejong/jsoneditor https://github.com/josdejong/jsoneditor
## not yet published, version 6.2.0 ## not yet published, version 6.2.0
- Implemented new mode `preview`, capable of working with JSON documents - Implemented new mode `preview`, capable of working with large JSON documents
up to 500 MiB. up to 500 MiB.
- Fixed #730: in `code` mode, there was an initial undo action which clears - Fixed #730: in `code` mode, there was an initial undo action which clears
the content. the content.
- Upgraded dependencies `vanilla-picker@2.9.1`, `mobius1-selectr@2.4.13`, - Upgraded dependencies `vanilla-picker@2.9.1`, `mobius1-selectr@2.4.13`,
`ajv@6.10.2`. `ajv@6.10.2`.
## 2019-06-22, version 6.1.0 ## 2019-06-22, version 6.1.0
- Implemented menu options `sort` and `transform` for modes `code` and `text`. - Implemented menu options `sort` and `transform` for modes `code` and `text`.

View File

@ -525,9 +525,7 @@ previewmode.get = function() {
var text = this.getText(); var text = this.getText();
try { try {
console.time('parse') // TODO: cleanup
this.json = util.parse(text); // this can throw an error this.json = util.parse(text); // this can throw an error
console.timeEnd('parse') // TODO: cleanup
} }
catch (err) { catch (err) {
// try to sanitize json, replace JavaScript notation with JSON notation // try to sanitize json, replace JavaScript notation with JSON notation
@ -547,14 +545,10 @@ previewmode.get = function() {
*/ */
previewmode.getText = function() { previewmode.getText = function() {
if (this.text === undefined) { if (this.text === undefined) {
console.time('stringify') // TODO: cleanup
this.text = JSON.stringify(this.json, null, this.indentation); this.text = JSON.stringify(this.json, null, this.indentation);
console.timeEnd('stringify') // TODO: cleanup
if (this.options.escapeUnicode === true) { if (this.options.escapeUnicode === true) {
console.time('escape') // TODO: cleanup
this.text = util.escapeUnicodeChars(this.text); this.text = util.escapeUnicodeChars(this.text);
console.timeEnd('escape') // TODO: cleanup
} }
} }
@ -594,9 +588,7 @@ previewmode.updateText = function(jsonText) {
*/ */
previewmode._setText = function(jsonText, json) { previewmode._setText = function(jsonText, json) {
if (this.options.escapeUnicode === true) { if (this.options.escapeUnicode === true) {
console.time('escape') // TODO: cleanup
this.text = util.escapeUnicodeChars(jsonText); this.text = util.escapeUnicodeChars(jsonText);
console.timeEnd('escape') // TODO: cleanup
} }
else { else {
this.text = jsonText; this.text = jsonText;
@ -605,7 +597,18 @@ previewmode._setText = function(jsonText, json) {
this._renderPreview(); this._renderPreview();
if (this.json === undefined) {
var me = this;
this.executeWithBusyMessage(function () {
// force parsing the json now, else it will be done in validate without feedback
me.json = me.get();
me._renderPreview();
me._pushHistory();
}, 'parsing...');
}
else {
this._pushHistory(); this._pushHistory();
}
this._debouncedValidate(); this._debouncedValidate();
}; };

View File

@ -252,14 +252,10 @@ function showTransformModal (container, json, onTransform) {
function updatePreview() { function updatePreview() {
try { try {
console.time('transform') // TODO: cleanup
var transformed = jmespath.search(value, query.value); var transformed = jmespath.search(value, query.value);
console.timeEnd('transform') // TODO: cleanup
console.time('stringify') // TODO: cleanup
preview.className = 'jsoneditor-transform-preview'; preview.className = 'jsoneditor-transform-preview';
preview.value = stringifyPartial(transformed, 2, MAX_PREVIEW_CHARACTERS); preview.value = stringifyPartial(transformed, 2, MAX_PREVIEW_CHARACTERS);
console.timeEnd('stringify') // TODO: cleanup
ok.disabled = false; ok.disabled = false;
} }