popcode icon indicating copy to clipboard operation
popcode copied to clipboard

Handle multi-line statements in the console

Open outoftime opened this issue 7 years ago • 4 comments

If a student types the following into the console and presses Enter:

if (name === "Pop") {

The console should recognize that it is an incomplete statement, and allow the student to keep typing (with an expanded input area to accommodate the new line).

This seems hard—how do we distinguish between an incomplete multiline statement and a statement that is syntactically invalid for some other reason? Perhaps Esprima or one of our other linters/parsers throws a specific “unexpected end of input” type error that we can rely on.

outoftime avatar Dec 09 '17 18:12 outoftime

Interesting that after typing if (name === "Pop") { and pressing Enter, it outputs SyntaxError: unexpected end of input but then next input line is indented.

alecmerdler avatar Nov 03 '18 17:11 alecmerdler

@alecmerdler yep although not super-surprising—the indentation behavior is almost certainly coming from built-in ACE formatting rules (which are sadly hit-or-miss in the broad scheme of things)

outoftime avatar Nov 03 '18 17:11 outoftime

At minimum we should also support Shift+Enter for entering newlines. Although this seems unnecessary since you have a full JS editor right there...

alecmerdler avatar Nov 03 '18 19:11 alecmerdler

Yo this would be a sweet feature. Chrome console does this really well and it's open source so theoretically this could use a similar implementation.

razzius avatar Jul 12 '19 02:07 razzius