Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: inconsistent Shift key behavior on Unix and Windows #174

Merged
merged 10 commits into from
Sep 20, 2023
24 changes: 19 additions & 5 deletions config/src/keymap/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,27 @@ impl Default for Key {

impl From<KeyEvent> for Key {
fn from(value: KeyEvent) -> Self {
let shift = matches!(value.code, KeyCode::Char(c) if c.is_ascii_uppercase());
sxyazi marked this conversation as resolved.
Show resolved Hide resolved
// For alphabet:
// Unix : <S-a> => Char("A") + SHIFT
// Windows : <S-a> => Char("A") + SHIFT
//
// For non-alphabet:
// Unix : <S-`> => Char("~") + NULL
// Windows : <S-`> => 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), _) => c.is_ascii_uppercase(),
(_, m) => m.contains(KeyModifiers::SHIFT),
};

Self {
code: value.code,
shift: shift || value.modifiers.contains(KeyModifiers::SHIFT),
ctrl: value.modifiers.contains(KeyModifiers::CONTROL),
alt: value.modifiers.contains(KeyModifiers::ALT),
code: value.code,
shift,
ctrl: value.modifiers.contains(KeyModifiers::CONTROL),
alt: value.modifiers.contains(KeyModifiers::ALT),
}
}
}
Expand Down