Skip to content

Commit

Permalink
Web: handle query string input line by line
Browse files Browse the repository at this point in the history
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.

Note that this is technically a breaking change:  existing numbat.dev
URLs in the wild that contain newlines in the middle of statements will
no longer work.

Closes #205
  • Loading branch information
eminence committed Oct 11, 2023
1 parent 69653b0 commit 7f4ea15
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions numbat-wasm/www/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ function interpret(input) {
output = result.output;

if (!result.is_error) {
combined_input += input + "\n";
combined_input += input.replace(/\n/g, " ") + "\n";
updateUrlQuery(combined_input.trim());
}
}
Expand Down Expand Up @@ -87,7 +87,10 @@ 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("\n")) {
term.exec(line + "\n");
}
}
}
});
Expand Down

0 comments on commit 7f4ea15

Please sign in to comment.