fix: preserve alt-shift letters (#1102)

refs #1088

Co-authored-by: akbash-bot <300245827+akbash-bot@users.noreply.github.com>
This commit is contained in:
akbash 2026-07-07 15:54:03 +03:00 committed by GitHub
parent b425260f9d
commit 39ba6b7a02
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 18 additions and 1 deletions

View File

@ -73,7 +73,11 @@ fn parse_legacy_key_sequence(data: &str) -> Option<TerminalKey> {
let rest = data.strip_prefix('\x1b')?;
if rest.chars().count() == 1 {
let ch = rest.chars().next()?;
Some(TerminalKey::new(KeyCode::Char(ch), KeyModifiers::ALT))
let mut modifiers = KeyModifiers::ALT;
if ch.is_ascii_uppercase() {
modifiers |= KeyModifiers::SHIFT;
}
Some(TerminalKey::new(KeyCode::Char(ch), modifiers))
} else {
None
}
@ -517,6 +521,19 @@ mod tests {
}
}
#[test]
fn parse_legacy_alt_shift_letter_preserves_shift() {
let key = parse_terminal_key_sequence("\x1bA").expect("alt-shift letter should parse");
assert_terminal_key_eq(
key,
KeyCode::Char('A'),
KeyModifiers::ALT | KeyModifiers::SHIFT,
crossterm::event::KeyEventKind::Press,
None,
);
assert_eq!(encode_terminal_key(key, KeyboardProtocol::Legacy), b"\x1bA");
}
#[test]
fn unknown_legacy_ss3_sequence_remains_unsupported() {
assert!(parse_terminal_key_sequence("\x1bOz").is_none());