Ignore keys with no valid KeyChar for vi movements #3928
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.
PR Summary
Add a new function called ReadKeyChar that loops until a key with valid KeyChar is read. Change the calls for ReadKey().KeyChar on .vi.cs files so that vi movements have this new behaviour.
The idea is to fix issues on Windows like not being able to move to characters that are behind dead keys on layouts such as US-international (single quotes, for example, is input only after hitting single quote and then space). The current behavior on Windows breaks the chain by returning a PSKeyInfo without a valid KeyChar and then trying to move to it (instead of waiting for the next key press to get the actual input).
PR Checklist
I'm not really sure how to unit test it since it seems dependent on the keyboard layout, but I welcome suggestions.
So far I've manually tested it on Windows running PowerShell 7.4.1 with Windows Terminal, conhost and Visual Studio Code and Linux (WSL2) with Windows Terminal.
The only caveaut I've found so far is that function keys (such as F1~F12) will also be ignored, But since the only code that is being changed to use the new version are the vi movement ones I believe this is not an issue.
Microsoft Reviewers: Open in CodeFlow