From a08802ea9f91d1ec1bbd2cd8c8caf7335ad50dce Mon Sep 17 00:00:00 2001 From: Sculas Date: Fri, 21 Jun 2024 02:40:58 +0200 Subject: [PATCH] fix(windows): coninput not handling control sequences (#1041) Thanks @robotastronaut for sharing their research in the Charm Discord server and for the initial fix. In contrast to their fix, this should fully align with the key handling on Unix and fix other issues like Shift+Tab not working on Windows. --- key_windows.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/key_windows.go b/key_windows.go index a5dbfc832c..b693efd655 100644 --- a/key_windows.go +++ b/key_windows.go @@ -39,9 +39,19 @@ func readConInputs(ctx context.Context, msgsch chan<- Msg, con windows.Handle) e } for i := 0; i < int(e.RepeatCount); i++ { + eventKeyType := keyType(e) + var runes []rune + + // Add the character only if the key type is an actual character and not a control sequence. + // This mimics the behavior in readAnsiInputs where the character is also removed. + // We don't need to handle KeySpace here. See the comment in keyType(). + if eventKeyType == KeyRunes { + runes = []rune{e.Char} + } + msgs = append(msgs, KeyMsg{ - Type: keyType(e), - Runes: []rune{e.Char}, + Type: eventKeyType, + Runes: runes, Alt: e.ControlKeyState.Contains(coninput.LEFT_ALT_PRESSED | coninput.RIGHT_ALT_PRESSED), }) }