-
Notifications
You must be signed in to change notification settings - Fork 5.2k
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
feat(repl): Add key binding to force a new line #14536
Conversation
@sigmaSd thanks for opening the PR. What's the reasoning for this functionality? If it is a popular binding, I'd expect that |
Would this also work on a Mac whereas Mac has the option key, not alt? |
I'm ok with any keybidings, if It doesn't work we can change it to ctrl but I don't have a mac to test. Regarding rustyline, it follows emacs and vi editor keys but the difference is in an editor the enter key is unambiguous it always means a new line, in a repl it can either mean a new line or a eval request, that's why we rely on heuristics such as is the parentheses balenced or not, but there are cases when heuristics can fail and you simply want to add a new line for example when refactoring a single to line to a multiline. I can add a demo of how this looks like if it's still unclear. |
Here is a random example where I want to refactor the initial one-liner to a function, In this case the heuristic would fail because the input is valid and it will try to evaluate it, that's why I'm forcing new lines. deno3.mov |
For precedence, I just noticed that fish shell has this feature and its also bound to Alt+enter |
@sigmaSd sounds good, we can add it. Please merge with |
done |
editor.bind_sequence( | ||
KeyEvent(KeyCode::Enter, Modifiers::ALT), | ||
EventHandler::Simple(Cmd::Newline), | ||
); |
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.
This doesn't seem to work in Windows terminal or command prompt—the terminal goes full screen when I press alt+enter.
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.
Guess its bound already, I can try ControlEnter or shiftEnter
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.
shiftenter and ctrlenter doesn't seem to work on linux, do you have a suggestion for a keybinding?
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.
I can also make it platform dependent, alt enter on Linux Mac, and maybe shift or ctrl enter on windows if one of those works
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.
I know @lucacasonato was interested in this issue. Luca WDYT?
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.
I changed the keybinding to CTRL-S, at least that should work cross platform.
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, thanks @sigmaSd!
@bartlomieju @dsherret In the blog post release notes, this is listed with a capital
However, the sequence requires lowercase Can it be changed to |
You mean you want to change the blog post to use |
@bartlomieju Yes, exactly.
Also, where is the official issue tracker for the blog? |
Sure I can change it.
You can post issues in |
@jsejcksn this is fixed now in the blog post. |
Add Alt Enter key binding to force a new line, usually this is used when you write a single line and then you want to break it.