Handle Repeat key events when using the crossterm backend #26
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.
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 onsrc/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: