From 2dbfc400a9058cbd84f5e061f8892d72c95e914f Mon Sep 17 00:00:00 2001 From: Sculas Date: Wed, 19 Jun 2024 00:27:44 +0200 Subject: [PATCH] fix(windows): Fix coninput not handling control sequences 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..4a810dd2f4 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), }) }