Skip to content

Commit

Permalink
Added fix for shift modifier
Browse files Browse the repository at this point in the history
  • Loading branch information
fritzrehde committed Aug 17, 2023
1 parent 8213ada commit 7220f9c
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/config/keybindings/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ enum KeyModifier {
Alt,
Ctrl,
#[from_str(ignore)]
Shift,
#[from_str(ignore)]
None,
}

Expand Down Expand Up @@ -85,7 +87,18 @@ impl TryFrom<CKeyEvent> for KeyEvent {
type Error = Error;
fn try_from(key: CKeyEvent) -> std::result::Result<Self, Self::Error> {
let code = key.code.try_into()?;
let modifier = key.modifiers.try_into()?;
let mut modifier = key.modifiers.try_into()?;

// We never internally save our modifier as Shift, because we don't
// want the user to have to specify e.g. "shift+G" instead of just "G".
// Therefore, we remove the Shift modifier if the code is uppercase
// anyways.
if let KeyCode::Char(char) = code {
if char.is_uppercase() && modifier == KeyModifier::Shift {
modifier = KeyModifier::None;
}
};

Ok(Self { modifier, code })
}
}
Expand All @@ -96,6 +109,7 @@ impl TryFrom<CKeyModifiers> for KeyModifier {
Ok(match value {
CKeyModifiers::ALT => Self::Alt,
CKeyModifiers::CONTROL => Self::Ctrl,
CKeyModifiers::SHIFT => Self::Shift,
CKeyModifiers::NONE => Self::None,
// TODO: shouldn't use debug output for display output
_ => bail!("Invalid modifier key: {:?}", value),
Expand Down

0 comments on commit 7220f9c

Please sign in to comment.