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
fix(repl): Accept tab when previous character is space #14898
Conversation
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.
Seems like a great usability addition; is it possible to add a test for this feature?
@dsherret please take a look too
struct TabEventHandler; | ||
impl ConditionalEventHandler for TabEventHandler { |
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.
Add a comment about the purpose of this
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.
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.
Thanks for this @sigmaSd! There are some pty tests for the repl here: https://github.com/denoland/deno/blob/main/cli/tests/integration/repl_tests.rs -- Would you be able to check if it's possible to add one for this?
) -> Option<Cmd> { | ||
debug_assert_eq!(*evt, Event::from(KeyEvent::from('\t'))); | ||
if ctx.line().is_empty() | ||
|| ctx.line()[..ctx.pos()] |
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.
To save other reviewers time, ctx.pos()
is indeed byte position https://docs.rs/rustyline/9.1.2/rustyline/struct.EventContext.html
I added a simple test, do you have some ideas to improve it? |
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!
This adds a heuristic that allows tabbing, if the user hits tab and the previous character on the line is white space he's most likely asking for an actual tab not completion.
Python repl for example does this.
tab.mov