From 08cbb328d103a7703d34602f595406caf0f1756c Mon Sep 17 00:00:00 2001 From: Andrew Chin Date: Tue, 10 Oct 2023 22:19:38 -0400 Subject: [PATCH] Web: handle query string input line by line This changes how input from a query string are handled. Handling them line by line produces output that more closely resembles how it would have looked like when typed in interactively. Closes #205 --- numbat-wasm/www/index.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/numbat-wasm/www/index.js b/numbat-wasm/www/index.js index 4c5c84ef..a887b62b 100644 --- a/numbat-wasm/www/index.js +++ b/numbat-wasm/www/index.js @@ -58,8 +58,8 @@ function interpret(input) { output = result.output; if (!result.is_error) { - combined_input += input + "\n"; - updateUrlQuery(combined_input.trim()); + combined_input += input.trim() + "⏎"; + updateUrlQuery(combined_input); } } @@ -87,7 +87,12 @@ function main() { if (location.search) { var queryParams = new URLSearchParams(location.search); if (queryParams.has("q")) { - term.exec(queryParams.get("q")); + // feed in the query line by line, as if the user typed it in + for (const line of queryParams.get("q").split("⏎")) { + if (line.trim().length > 0) { + term.exec(line.trim() + "\n"); + } + } } } });