Add support for combining some modifier keys (#518)
This commit is contained in:
parent
0797441893
commit
744ec05f19
@ -57,12 +57,16 @@ pub(crate) fn parse_event(buffer: &[u8], input_available: bool) -> Result<Option
|
|||||||
}
|
}
|
||||||
b'[' => parse_csi(buffer),
|
b'[' => parse_csi(buffer),
|
||||||
b'\x1B' => Ok(Some(InternalEvent::Event(Event::Key(KeyCode::Esc.into())))),
|
b'\x1B' => Ok(Some(InternalEvent::Event(Event::Key(KeyCode::Esc.into())))),
|
||||||
_ => parse_utf8_char(&buffer[1..]).map(|maybe_char| {
|
_ => parse_event(&buffer[1..], input_available).map(|event_option| {
|
||||||
maybe_char
|
event_option.map(|event| {
|
||||||
.map(KeyCode::Char)
|
if let InternalEvent::Event(Event::Key(key_event)) = event {
|
||||||
.map(|code| KeyEvent::new(code, KeyModifiers::ALT))
|
let mut alt_key_event = key_event;
|
||||||
.map(Event::Key)
|
alt_key_event.modifiers |= KeyModifiers::ALT;
|
||||||
.map(InternalEvent::Event)
|
InternalEvent::Event(Event::Key(alt_key_event))
|
||||||
|
} else {
|
||||||
|
event
|
||||||
|
}
|
||||||
|
})
|
||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -491,6 +495,28 @@ mod tests {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_alt_shift() {
|
||||||
|
assert_eq!(
|
||||||
|
parse_event(b"\x1BH", false).unwrap(),
|
||||||
|
Some(InternalEvent::Event(Event::Key(KeyEvent::new(
|
||||||
|
KeyCode::Char('H'),
|
||||||
|
KeyModifiers::ALT | KeyModifiers::SHIFT
|
||||||
|
)))),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_alt_ctrl() {
|
||||||
|
assert_eq!(
|
||||||
|
parse_event(b"\x1B\x14", false).unwrap(),
|
||||||
|
Some(InternalEvent::Event(Event::Key(KeyEvent::new(
|
||||||
|
KeyCode::Char('t'),
|
||||||
|
KeyModifiers::ALT | KeyModifiers::CONTROL
|
||||||
|
)))),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_parse_event_subsequent_calls() {
|
fn test_parse_event_subsequent_calls() {
|
||||||
// The main purpose of this test is to check if we're passing
|
// The main purpose of this test is to check if we're passing
|
||||||
|
Loading…
Reference in New Issue
Block a user