Skip to content
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

Merged
merged 3 commits into from Jun 20, 2022

Conversation

sigmaSd
Copy link
Contributor

@sigmaSd sigmaSd commented Jun 17, 2022

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

Copy link
Member

@bartlomieju bartlomieju left a 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

@bartlomieju bartlomieju added this to the 1.24 milestone Jun 19, 2022
Comment on lines +400 to +401
struct TabEventHandler;
impl ConditionalEventHandler for TabEventHandler {
Copy link
Member

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Member

@dsherret dsherret left a 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()]
Copy link
Member

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

@sigmaSd
Copy link
Contributor Author

sigmaSd commented Jun 20, 2022

I added a simple test, do you have some ideas to improve it?

@dsherret dsherret removed this from the 1.24 milestone Jun 20, 2022
@dsherret dsherret changed the title feat(repl): Accept tab when previous character is space fix(repl): Accept tab when previous character is space Jun 20, 2022
Copy link
Member

@dsherret dsherret left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks @sigmaSd!

@dsherret dsherret merged commit ac2cf2c into denoland:main Jun 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants