Revert "fix shift character keymap"

This reverts commit d5347fc697.
This commit is contained in:
Nguyen Duc Toan 2023-09-20 21:10:33 +07:00
parent 3ee8ef8547
commit 91ab4ea676

View file

@ -2,7 +2,7 @@ use anyhow::bail;
use crossterm::event::{KeyCode, KeyEvent, KeyModifiers};
use serde::Deserialize;
#[derive(Clone, Debug, Deserialize, Eq)]
#[derive(Clone, Debug, Deserialize, PartialEq, Eq, Hash)]
#[serde(try_from = "String")]
pub struct Key {
pub code: KeyCode,
@ -11,22 +11,6 @@ pub struct Key {
pub alt: bool,
}
impl PartialEq for Key {
fn eq(&self, other: &Self) -> bool {
match (self.code, other.code) {
(KeyCode::Char(_), KeyCode::Char(_)) => {
self.code == other.code && self.ctrl == other.ctrl && self.alt == other.alt
}
_ => {
self.code == other.code
&& self.shift == other.shift
&& self.ctrl == other.ctrl
&& self.alt == other.alt
}
}
}
}
impl Key {
#[inline]
pub fn plain(&self) -> Option<char> {
@ -43,16 +27,16 @@ impl Key {
}
impl Default for Key {
fn default() -> Self {
Self { code: KeyCode::Null, shift: false, ctrl: false, alt: false }
}
fn default() -> Self { Self { code: KeyCode::Null, shift: false, ctrl: false, alt: false } }
}
impl From<KeyEvent> for Key {
fn from(value: KeyEvent) -> Self {
let shift = matches!(value.code, KeyCode::Char(c) if c.is_ascii_uppercase());
Self {
code: value.code,
shift: value.modifiers.contains(KeyModifiers::SHIFT),
shift: shift || value.modifiers.contains(KeyModifiers::SHIFT),
ctrl: value.modifiers.contains(KeyModifiers::CONTROL),
alt: value.modifiers.contains(KeyModifiers::ALT),
}
@ -71,6 +55,7 @@ impl TryFrom<String> for Key {
if !s.starts_with('<') || !s.ends_with('>') {
let c = s.chars().next().unwrap();
key.code = KeyCode::Char(c);
key.shift = c.is_ascii_uppercase();
return Ok(key);
}