fix: KeyModifiers Display impl (#979)

The KeyModifiers Display implementation incorrectly formatted modifier keys, causing the output to be concatenated without + separators. This is now corrected.
This commit is contained in:
Flokkq 2025-03-22 23:41:25 +01:00 committed by GitHub
parent 69249c88fe
commit 2d3f3f5636
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -870,8 +870,9 @@ impl Display for KeyModifiers {
for modifier in self.iter() {
if !first {
f.write_str("+")?;
first = false;
}
first = false;
match modifier {
KeyModifiers::SHIFT => f.write_str("Shift")?,
#[cfg(unix)]
@ -1625,6 +1626,20 @@ mod tests {
assert_eq!(format!("{}", Modifier(RightSuper)), "Right Super");
}
#[test]
fn key_modifiers_display() {
let modifiers = KeyModifiers::SHIFT | KeyModifiers::CONTROL | KeyModifiers::ALT;
#[cfg(target_os = "macos")]
assert_eq!(modifiers.to_string(), "Shift+Control+Option");
#[cfg(target_os = "windows")]
assert_eq!(modifiers.to_string(), "Shift+Ctrl+Alt");
#[cfg(not(any(target_os = "macos", target_os = "windows")))]
assert_eq!(modifiers.to_string(), "Shift+Control+Alt");
}
const ESC_PRESSED: KeyEvent =
KeyEvent::new_with_kind(KeyCode::Esc, KeyModifiers::empty(), KeyEventKind::Press);
const ESC_RELEASED: KeyEvent =