Guard against JSON.parse errors.

Also show successful style parse status after a style error was corrected
but it is the same style as previously.
This commit is contained in:
Maximilian Krög
2019-10-03 00:17:33 +02:00
parent db34a338d6
commit dee114d4c4

View File

@@ -81,13 +81,12 @@ function setStyleStatus(valid) {
const editor = document.getElementById('style-editor');
editor.addEventListener('input', function() {
const textStyle = editor.value;
if (JSON.stringify(JSON.parse(textStyle)) === JSON.stringify(literalStyle)) {
return;
}
try {
literalStyle = JSON.parse(textStyle);
refreshLayer();
const newLiteralStyle = JSON.parse(textStyle);
if (JSON.stringify(newLiteralStyle) !== JSON.stringify(literalStyle)) {
literalStyle = newLiteralStyle;
refreshLayer();
}
setStyleStatus(true);
} catch (e) {
setStyleStatus(false);