keymap: Detect and report errors for uppercase keybindings (#27558)

Closes #25353

Detect keybindings using upper case instead of lowercase, and report an
error

Release Notes:

- N/A
This commit is contained in:
Ben Kunkle 2025-03-27 17:17:43 -04:00 committed by GitHub
parent 3b158461be
commit 8e12eb0ab1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 123 additions and 58 deletions

View file

@ -240,15 +240,18 @@ pub fn to_esc_str(keystroke: &Keystroke, mode: &TermMode, alt_is_meta: bool) ->
}
}
let alt_meta_binding =
if alt_is_meta && modifiers == AlacModifiers::Alt && keystroke.key.is_ascii() {
Some(format!("\x1b{}", keystroke.key))
} else {
None
};
if alt_meta_binding.is_some() {
return alt_meta_binding;
if alt_is_meta {
let is_alt_lowercase_ascii = modifiers == AlacModifiers::Alt && keystroke.key.is_ascii();
let is_alt_uppercase_ascii =
keystroke.modifiers.alt && keystroke.modifiers.shift && keystroke.key.is_ascii();
if is_alt_lowercase_ascii || is_alt_uppercase_ascii {
let key = if is_alt_uppercase_ascii {
&keystroke.key.to_ascii_uppercase()
} else {
&keystroke.key
};
return Some(format!("\x1b{}", key));
}
}
None
@ -390,12 +393,12 @@ mod test {
for (lower, upper) in letters_lower.zip(letters_upper) {
assert_eq!(
to_esc_str(
&Keystroke::parse(&format!("ctrl-{}", lower)).unwrap(),
&Keystroke::parse(&format!("ctrl-shift-{}", lower)).unwrap(),
&mode,
false
),
to_esc_str(
&Keystroke::parse(&format!("ctrl-shift-{}", upper)).unwrap(),
&Keystroke::parse_case_insensitive(&format!("ctrl-{}", upper)).unwrap(),
&mode,
false
),
@ -412,7 +415,7 @@ mod test {
for character in ascii_printable {
assert_eq!(
to_esc_str(
&Keystroke::parse(&format!("alt-{}", character)).unwrap(),
&Keystroke::parse_case_insensitive(&format!("alt-{}", character)).unwrap(),
&TermMode::NONE,
true
)
@ -453,15 +456,15 @@ mod test {
// 8 | Shift + Alt + Control
// ---------+---------------------------
// from: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h2-PC-Style-Function-Keys
assert_eq!(2, modifier_code(&Keystroke::parse("shift-A").unwrap()));
assert_eq!(3, modifier_code(&Keystroke::parse("alt-A").unwrap()));
assert_eq!(4, modifier_code(&Keystroke::parse("shift-alt-A").unwrap()));
assert_eq!(5, modifier_code(&Keystroke::parse("ctrl-A").unwrap()));
assert_eq!(6, modifier_code(&Keystroke::parse("shift-ctrl-A").unwrap()));
assert_eq!(7, modifier_code(&Keystroke::parse("alt-ctrl-A").unwrap()));
assert_eq!(2, modifier_code(&Keystroke::parse("shift-a").unwrap()));
assert_eq!(3, modifier_code(&Keystroke::parse("alt-a").unwrap()));
assert_eq!(4, modifier_code(&Keystroke::parse("shift-alt-a").unwrap()));
assert_eq!(5, modifier_code(&Keystroke::parse("ctrl-a").unwrap()));
assert_eq!(6, modifier_code(&Keystroke::parse("shift-ctrl-a").unwrap()));
assert_eq!(7, modifier_code(&Keystroke::parse("alt-ctrl-a").unwrap()));
assert_eq!(
8,
modifier_code(&Keystroke::parse("shift-ctrl-alt-A").unwrap())
modifier_code(&Keystroke::parse("shift-ctrl-alt-a").unwrap())
);
}
}