diff --git a/config/src/keymap/key.rs b/config/src/keymap/key.rs index 9af5047e..25f45b9a 100644 --- a/config/src/keymap/key.rs +++ b/config/src/keymap/key.rs @@ -32,16 +32,17 @@ impl Default for Key { impl From for Key { fn from(value: KeyEvent) -> Self { - /* - On Linx and Mac: - shift + alphabet => uppercase alphabet + SHIFT - shift + non alphabet => shifted non alphabet + NULL - On Windows: - shift + alphabet => uppercase alphabet + SHIFT - shift + non alphabet => shifted non alphabet + SHIFT - So we detect (non alphabet + SHIFT) and change it to (non alphabet + NULL) for consistent - behavior between OSs. - */ + // For alphabet: + // Unix : => Char("A") + Shift + // Windows : => Char("A") + Shift + // + // For non-alphabet: + // Unix : => Char("~") + NULL + // Windows : => Char("`") + Shift + // + // So we detect `Char("`") + Shift`, and change it to `Char("~") + NULL` + // for consistent behavior between OSs. + let shift = match (value.code, value.modifiers) { (KeyCode::Char(c), _) if c.is_ascii_uppercase() => true, (KeyCode::Char(_), m) if m.contains(KeyModifiers::SHIFT) => false, @@ -49,10 +50,10 @@ impl From for Key { }; Self { - code: value.code, + code: value.code, shift, - ctrl: value.modifiers.contains(KeyModifiers::CONTROL), - alt: value.modifiers.contains(KeyModifiers::ALT), + ctrl: value.modifiers.contains(KeyModifiers::CONTROL), + alt: value.modifiers.contains(KeyModifiers::ALT), } } }