Skip to content

fix: don't rely on value from GetNumberOfConsoleInputEvents#15

Merged
the-mikedavis merged 1 commit intohelix-editor:masterfrom
aschey:fix/unicode-input-read
Jan 18, 2026
Merged

fix: don't rely on value from GetNumberOfConsoleInputEvents#15
the-mikedavis merged 1 commit intohelix-editor:masterfrom
aschey:fix/unicode-input-read

Conversation

@aschey
Copy link
Copy Markdown
Contributor

@aschey aschey commented Jan 4, 2026

The value returned from GetNumberOfConsoleInputEvents matches what you would get when calling ReadConsoleInputW, but this does not always match the number of results from ReadConsoleInputA when typing some Unicode characters that differ in UTF-8/UTF-16 encoding. As a result, some Unicode characters were not fully read on the initial keystroke and did not show up until you typed them twice. Thankfully, ReadConsoleInputA tells us how many results are returned anyway, so we can just initialize it with a sufficiently large buffer and only use GetNumberOfConsoleInputEvents to determine if there are >0 pending events.

This should fix the reports from people claiming they had to type in certain keys more than once or some characters weren't appearing (helix-editor/helix#14637 (comment), helix-editor/helix#14363 (comment)). I wasn't able to reproduce the IME input hanging (helix-editor/helix#14387), so I'm not sure if this will be fixed, but it might.

The other issues on Windows, such as certain keys like <Ctrl-,> not working, will still require implementing the legacy protocol for some users, since Windows Terminal (among others) doesn't implement the Kitty Keyboard protocol. I'm working on this in another branch.

Copy link
Copy Markdown
Member

@the-mikedavis the-mikedavis left a comment

Choose a reason for hiding this comment

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

Awesome, thanks for digging into this @aschey! I just have a tiny style nit

Comment thread src/terminal/windows.rs Outdated
Comment on lines +95 to +96
impl Debug for InputHandle {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

for Debug I like to import std::fmt and then impl fmt::Debug for T { .. }, since it means we can use fmt::Formatter and fmt::Result in the signature here

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Makes sense, done!

@aschey aschey force-pushed the fix/unicode-input-read branch from e029da2 to 6c71085 Compare January 5, 2026 19:11
Copy link
Copy Markdown
Member

@the-mikedavis the-mikedavis left a comment

Choose a reason for hiding this comment

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

Thanks! (Sorry for the delay, this got trapped under a pile of other notifications 😅.)

And great to keep the docs/windows-vt.md doc up to date. This is something I really wish Microsoft would document, even if it were just C++ code samples. I'm not sure I've seen a good example that fully covers reading VT.

@the-mikedavis the-mikedavis merged commit 2fa054c into helix-editor:master Jan 18, 2026
9 checks passed
@aschey aschey deleted the fix/unicode-input-read branch January 18, 2026 20:01
@aschey
Copy link
Copy Markdown
Contributor Author

aschey commented Jan 19, 2026

No worries, thanks! I agree - I've had a pretty difficult time trying to make sense of all the quirks between the legacy and VTE input reader modes. Code samples and more detailed explanations of the tradeoffs would be most welcome.

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