Skip to content

Commit 2d3f3f5

Browse files
authored
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.
1 parent 69249c8 commit 2d3f3f5

1 file changed

Lines changed: 16 additions & 1 deletion

File tree

src/event.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -870,8 +870,9 @@ impl Display for KeyModifiers {
870870
for modifier in self.iter() {
871871
if !first {
872872
f.write_str("+")?;
873-
first = false;
874873
}
874+
875+
first = false;
875876
match modifier {
876877
KeyModifiers::SHIFT => f.write_str("Shift")?,
877878
#[cfg(unix)]
@@ -1625,6 +1626,20 @@ mod tests {
16251626
assert_eq!(format!("{}", Modifier(RightSuper)), "Right Super");
16261627
}
16271628

1629+
#[test]
1630+
fn key_modifiers_display() {
1631+
let modifiers = KeyModifiers::SHIFT | KeyModifiers::CONTROL | KeyModifiers::ALT;
1632+
1633+
#[cfg(target_os = "macos")]
1634+
assert_eq!(modifiers.to_string(), "Shift+Control+Option");
1635+
1636+
#[cfg(target_os = "windows")]
1637+
assert_eq!(modifiers.to_string(), "Shift+Ctrl+Alt");
1638+
1639+
#[cfg(not(any(target_os = "macos", target_os = "windows")))]
1640+
assert_eq!(modifiers.to_string(), "Shift+Control+Alt");
1641+
}
1642+
16281643
const ESC_PRESSED: KeyEvent =
16291644
KeyEvent::new_with_kind(KeyCode::Esc, KeyModifiers::empty(), KeyEventKind::Press);
16301645
const ESC_RELEASED: KeyEvent =

0 commit comments

Comments
 (0)