Fix showing parse error in mode `text` and `preview`

This commit is contained in:
jos 2019-07-24 15:26:01 +02:00
parent 2b6caba3df
commit fb30ded5fa
2 changed files with 11 additions and 27 deletions

View File

@ -524,16 +524,7 @@ previewmode.get = function() {
if (this.json === undefined) { if (this.json === undefined) {
var text = this.getText(); var text = this.getText();
try { this.json = util.parse(text); // this can throw an error
this.json = util.parse(text); // this can throw an error
}
catch (err) {
// try to sanitize json, replace JavaScript notation with JSON notation
text = util.sanitize(text);
// try to parse again
this.json = util.parse(text); // this can throw an error
}
} }
return this.json; return this.json;
@ -600,10 +591,15 @@ previewmode._setText = function(jsonText, json) {
if (this.json === undefined) { if (this.json === undefined) {
var me = this; var me = this;
this.executeWithBusyMessage(function () { this.executeWithBusyMessage(function () {
// force parsing the json now, else it will be done in validate without feedback try {
me.json = me.get(); // force parsing the json now, else it will be done in validate without feedback
me._renderPreview(); me.json = me.get();
me._pushHistory(); me._renderPreview();
me._pushHistory();
}
catch (err) {
// no need to throw an error, validation will show an error
}
}, 'parsing...'); }, 'parsing...');
} }
else { else {

View File

@ -690,20 +690,8 @@ textmode.update = function(json) {
*/ */
textmode.get = function() { textmode.get = function() {
var text = this.getText(); var text = this.getText();
var json;
try { return util.parse(text); // this can throw an error
json = util.parse(text); // this can throw an error
}
catch (err) {
// try to sanitize json, replace JavaScript notation with JSON notation
text = util.sanitize(text);
// try to parse again
json = util.parse(text); // this can throw an error
}
return json;
}; };
/** /**