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

Handle Repeat key events when using the crossterm backend #26

Merged
merged 1 commit into from
Nov 27, 2024

Conversation

cxreiff
Copy link
Contributor

@cxreiff cxreiff commented Nov 27, 2024

Problem

In certain terminal environments where holding a key sends multiple Press events, tui-input's key event handler works as expected. However in terminal environments that properly support Repeat key events, tui-input will toss out those events because of the enum equality check on src/backend/crossterm.rs:22. For example, pressing and holding a character will only type a single, initial character.

Solution

Adding KeyEventKind::Repeat to the match arm condition means that Repeat events will be handled correctly, while Release events will continue to be ignored.

Testing

Added a unit test, and tested the examples.

Note

Most of the green/red in the diff below is an indent from the formatter, the significant change is just line 22:

}) if *kind == KeyEventKind::Press || *kind == KeyEventKind::Repeat => {

@sayanarijit
Copy link
Owner

Thank you...

@sayanarijit sayanarijit merged commit 75b14d5 into sayanarijit:main Nov 27, 2024
1 check passed
@cxreiff cxreiff deleted the handle-repeat-events branch November 27, 2024 09:20
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.

2 participants