-
-
Notifications
You must be signed in to change notification settings - Fork 830
feat: add multiline editing in the REPL #2347
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Signed-off-by: Snehil Shah <[email protected]>
Signed-off-by: Snehil Shah <[email protected]>
Signed-off-by: Snehil Shah <[email protected]>
Signed-off-by: Snehil Shah <[email protected]>
Signed-off-by: Snehil Shah <[email protected]>
Signed-off-by: Snehil Shah <[email protected]>
Signed-off-by: Snehil Shah <[email protected]>
Signed-off-by: Snehil Shah <[email protected]>
@Snehil-Shah After pulling this down and playing with things, I was able to get the REPL into a state where I was stuck in multi-line edit mode and the command cache was not being cleared. Even after executing subsequent commands, anytime I hit enter from a new command prompt, rather than execute an empty statement, the REPL would re-enter multi-line mode. Looks like some edge cases are not being fully handled. |
Also, when I did the following
and hit Ctrl+E, the REPL did not break the line at the cursor. Instead, it did
which is not what is typically desired.. |
@kgryte I think I found out what's really going on. So, the thing is, I have been testing this out with CTRL+O combination all this time because apparently CTRL+E was clashing with my editor's internal keybinding (yes I got lazy there in changing my editor preferences, I apologize). I now tried CTRL+E. Apparently, in node's readline, CTRL+E has a default keypress action of "to end of line". So everytime we do ctrl+e, we go to the end of the line and then we enter multiline editing. That's the reason your curly braces example is doing what it's doing.
That was intentional and not a problem with the cache. I thought empty statements don't mean anything so it would be better to assume they are trying to type more, maybe to have equal indentation by starting from below the prompt and they can always use backspace to go back.
I'll change it if it's not desired or correct. |
Re: keybinding. Re: empty statements. I found the updated behavior surprising. My feeling is that we should treat statements (including empty statements) consistently. Meaning,
and
should behave consistently when hitting ENTER. And to enter multi-line mode in both instances, one needs to use the |
Signed-off-by: Snehil Shah <[email protected]>
@kgryte done. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. I pulled down locally and tested out. Seems to work as stated.
As stated in the OP, we'll want to figure out the previous command/history issue. And moving from processLine
to a dedicated multi-line handler class significantly increases complexity, requiring fairly tight coupling between various components. This class is a good candidate for a future refactor in order to disentangle logic. For now, however, I'm fine with punting this to another day.
Thanks for working on this, @Snehil-Shah!
Resolves #2060
Description
This pull request:
CTRL+O
keybinding.Related Issues
This pull request:
Questions
Testing strategy?
Other
I wanted to clarify a mistake in the original RFC and that hitting the up arrow auto-completes the previous commands only if the line is empty. After this PR, this behavior is preserved. Only when you have an empty input, the up arrow completions will work.
I will add the ability to cycle through multiline commands using the up arrow, in a separate PR.
Checklist
@stdlib-js/reviewers