From 5ef7cb27500be632e39cac12afbc7a23f22db221 Mon Sep 17 00:00:00 2001 From: Brian Carroll Date: Fri, 7 Oct 2022 08:26:31 +0100 Subject: [PATCH] www: handle empty input in web REPL --- www/public/repl/repl.js | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/www/public/repl/repl.js b/www/public/repl/repl.js index 0c64ca4f72..91248858f7 100644 --- a/www/public/repl/repl.js +++ b/www/public/repl/repl.js @@ -42,7 +42,7 @@ const repl = { repl.elemSourceInput.addEventListener("change", onInputChange); repl.elemSourceInput.addEventListener("keyup", onInputKeyup); roc_repl_wasm.default("/repl/roc_repl_wasm_bg.wasm").then((instance) => { - repl.elemHistory.querySelector('#loading-message').remove(); + repl.elemHistory.querySelector("#loading-message").remove(); repl.elemSourceInput.disabled = false; repl.elemSourceInput.placeholder = "Type some Roc code and press Enter. (Use Shift+Enter for multi-line input)"; @@ -54,8 +54,7 @@ roc_repl_wasm.default("/repl/roc_repl_wasm_bg.wasm").then((instance) => { // ---------------------------------------------------------------------------- function onInputChange(event) { - const inputText = event.target.value; - if (!inputText) return; + const inputText = event.target.value.trim(); event.target.value = ""; @@ -122,13 +121,15 @@ async function processInputQueue() { repl.inputHistoryIndex = createHistoryEntry(inputText); repl.inputStash = ""; - let outputText; + let outputText = ""; let ok = true; - try { - outputText = await roc_repl_wasm.entrypoint_from_js(inputText); - } catch (e) { - outputText = `${e}`; - ok = false; + if (inputText) { + try { + outputText = await roc_repl_wasm.entrypoint_from_js(inputText); + } catch (e) { + outputText = `${e}`; + ok = false; + } } updateHistoryEntry(repl.inputHistoryIndex, ok, outputText);