Refactor: is press

This commit is contained in:
chiehw 2023-03-22 08:17:11 +08:00 committed by asur4s
parent e99af2b0d4
commit 8478c2ba48

View File

@ -862,6 +862,10 @@ fn is_altgr(event: &Event) -> bool {
}
}
fn is_press(event: &Event) -> bool {
matches!(event.event_type, EventType::KeyPress(_))
}
pub fn translate_keyboard_mode(peer: &str, event: &Event, key_event: KeyEvent) -> Vec<KeyEvent> {
let mut events: Vec<KeyEvent> = Vec::new();
if let Some(unicode_info) = &event.unicode {
@ -887,8 +891,8 @@ pub fn translate_keyboard_mode(peer: &str, event: &Event, key_event: KeyEvent) -
return events;
}
#[cfg(target_os = "windows")]
if matches!(event.event_type, EventType::KeyPress(_)) {
#[cfg(any(target_os = "linux", target_os = "windows"))]
if is_press(event) {
try_fill_unicode(event, &key_event, &mut events);
}
@ -899,9 +903,6 @@ pub fn translate_keyboard_mode(peer: &str, event: &Event, key_event: KeyEvent) -
}
}
#[cfg(target_os = "linux")]
try_fill_unicode(event, &key_event, &mut events);
#[cfg(target_os = "macos")]
if !unsafe { IS_LEFT_OPTION_DOWN } {
try_fill_unicode(event, &key_event, &mut events);