-
Notifications
You must be signed in to change notification settings - Fork 178
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
Do not validate if the command is 'NewLine' #640
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Related to #379. |
I would prefer that we don't call diff --git a/src/command.rs b/src/command.rs
index b46c7d5..c16f966 100644
--- a/src/command.rs
+++ b/src/command.rs
@@ -25,6 +25,16 @@ pub fn execute<H: Helper>(
) -> Result<Status> {
use Status::{Proceed, Submit};
+ match cmd {
+ Cmd::EndOfFile | Cmd::AcceptLine | Cmd::AcceptOrInsertLine { .. } | Cmd::Newline => {
+ if s.has_hint() || !s.is_default_prompt() {
+ // Force a refresh without hints to leave the previous
+ // line as the user typed it after a newline.
+ s.refresh_line_with_msg(None)?;
+ }
+ }
+ _ => {}
+ };
match cmd {
Cmd::CompleteHint => {
complete_hint_line(s)?;
@@ -58,11 +68,6 @@ pub fn execute<H: Helper>(
s.edit_overwrite_char(c)?;
}
Cmd::EndOfFile => {
- if s.has_hint() || !s.is_default_prompt() {
- // Force a refresh without hints to leave the previous
- // line as the user typed it after a newline.
- s.refresh_line_with_msg(None)?;
- }
if s.line.is_empty() {
return Err(error::ReadlineError::Eof);
} else if !input_state.is_emacs_mode() {
@@ -119,12 +124,10 @@ pub fn execute<H: Helper>(
kill_ring.kill(&text, Mode::Append);
}
}
- Cmd::AcceptLine | Cmd::AcceptOrInsertLine { .. } | Cmd::Newline => {
- if s.has_hint() || !s.is_default_prompt() {
- // Force a refresh without hints to leave the previous
- // line as the user typed it after a newline.
- s.refresh_line_with_msg(None)?;
- }
+ Cmd::Newline => {
+ s.edit_insert('\n', 1)?;
+ }
+ Cmd::AcceptLine | Cmd::AcceptOrInsertLine { .. } => {
let validation_result = s.validate()?;
let valid = validation_result.is_valid();
let end = s.line.is_end_of_input();
@@ -140,8 +143,7 @@ pub fn execute<H: Helper>(
) => {
return Ok(Submit);
}
- (Cmd::Newline, ..)
- | (Cmd::AcceptOrInsertLine { .. }, false, _)
+ (Cmd::AcceptOrInsertLine { .. }, false, _)
| (Cmd::AcceptOrInsertLine { .. }, true, false) => {
if valid || !validation_result.has_message() {
s.edit_insert('\n', 1)?; |
done |
gwenn
approved these changes
Jul 15, 2022
Thanks. |
Would you mind releasing a new version? I want to add this to deno repl |
I will try this week-end. |
Thanks! |
Version 10.0.0 released. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
NewLine
is in my experience used when the user actually want to force a newline regardless of the result of the validation.This pr exempt newline from validation.
demo: (I first hit enter each time then ctrl-s)