mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
fix: inconsistent Shift key behavior on Unix and Windows (#174)
This commit is contained in:
parent
6d2f69b612
commit
4065a0573a
1 changed files with 19 additions and 5 deletions
|
|
@ -32,13 +32,27 @@ impl Default for Key {
|
||||||
|
|
||||||
impl From<KeyEvent> for Key {
|
impl From<KeyEvent> for Key {
|
||||||
fn from(value: KeyEvent) -> Self {
|
fn from(value: KeyEvent) -> Self {
|
||||||
let shift = matches!(value.code, KeyCode::Char(c) if c.is_ascii_uppercase());
|
// 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 {
|
Self {
|
||||||
code: value.code,
|
code: value.code,
|
||||||
shift: shift || value.modifiers.contains(KeyModifiers::SHIFT),
|
shift,
|
||||||
ctrl: value.modifiers.contains(KeyModifiers::CONTROL),
|
ctrl: value.modifiers.contains(KeyModifiers::CONTROL),
|
||||||
alt: value.modifiers.contains(KeyModifiers::ALT),
|
alt: value.modifiers.contains(KeyModifiers::ALT),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue