From c80c31e7bbbfb7658490d5eb56995ac8ad38f583 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Sat, 30 Nov 2019 10:09:30 +0100 Subject: [PATCH] Controlling JSON syntax at UI Objects properties --- FloatingSpace/CodeEditor.js | 8 ++++++++ FloatingSpace/UiObject.js | 5 +++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/FloatingSpace/CodeEditor.js b/FloatingSpace/CodeEditor.js index 1ed862964..62fcffdae 100644 --- a/FloatingSpace/CodeEditor.js +++ b/FloatingSpace/CodeEditor.js @@ -71,6 +71,13 @@ function newCodeEditor () { let textArea = document.getElementById('textArea') textArea.style.display = 'none' thisObject.payload.node.code = textArea.value + if (thisObject.payload.node.type !== 'Code' && thisObject.payload.node.type !== 'Formula') { + try { + let code = JSON.parse(thisObject.payload.node.code) + } catch (err) { + thisObject.payload.uiObject.setErrorMessage(err.message, 10) + } + } } } @@ -80,6 +87,7 @@ function newCodeEditor () { thisObject.rawRadius = 8 thisObject.targetRadius = thisObject.container.frame.radius thisObject.currentRadius = 0 + thisObject.payload.uiObject.setErrorMessage('', 0) let textArea = document.getElementById('textArea') textArea.value = payload.node.code diff --git a/FloatingSpace/UiObject.js b/FloatingSpace/UiObject.js index 55506b4c0..f702b5e60 100644 --- a/FloatingSpace/UiObject.js +++ b/FloatingSpace/UiObject.js @@ -835,11 +835,12 @@ function newUiObject () { highlightCounter = 30 } - function setErrorMessage (message) { + function setErrorMessage (message, duration) { if (message !== undefined) { errorMessage = message hasError = true - errorMessageCounter = 100 + if (duration === undefined) { duration = 1 } + errorMessageCounter = 100 * duration } }