fix(keyevent): do not emit default ignorable codepoint

This commit is contained in:
OJ Kwon 2018-03-17 23:09:31 -07:00
parent fd60007a28
commit da586d0994
No known key found for this signature in database
GPG key ID: FFCFEF3460FD1901

View file

@ -346,8 +346,32 @@ impl Window {
GlRequest::Specific(Api::OpenGlEs, (3, 0)) GlRequest::Specific(Api::OpenGlEs, (3, 0))
} }
/// Detect if given char is default ignorable in unicode
/// http://www.unicode.org/L2/L2002/02368-default-ignorable.pdf
fn is_identifier_ignorable(&self, ch: &char) -> bool {
match *ch {
'\u{0000}'...'\u{0008}' | '\u{000E}'...'\u{001F}' |
'\u{007F}'...'\u{0084}' | '\u{0086}'...'\u{009F}' |
'\u{06DD}' | '\u{070F}' |
'\u{180B}'...'\u{180D}' | '\u{180E}' |
'\u{200C}'...'\u{200F}' |
'\u{202A}'...'\u{202E}' | '\u{2060}'...'\u{2063}' |
'\u{2064}'...'\u{2069}' | '\u{206A}'...'\u{206F}' |
'\u{FE00}'...'\u{FE0F}' | '\u{FEFF}' |
'\u{FFF0}'...'\u{FFF8}' | '\u{FFF9}'...'\u{FFFB}' |
'\u{1D173}'...'\u{1D17A}' | '\u{E0000}' |
'\u{E0001}' |
'\u{E0002}'...'\u{E001F}' | '\u{E0020}'...'\u{E007F}' |
'\u{E0080}'...'\u{E0FFF}' => true,
_ => false
}
}
fn handle_received_character(&self, ch: char) { fn handle_received_character(&self, ch: char) {
let modifiers = Window::glutin_mods_to_script_mods(self.key_modifiers.get()); let modifiers = Window::glutin_mods_to_script_mods(self.key_modifiers.get());
if self.is_identifier_ignorable(&ch) {
return
}
if let Some(last_pressed_key) = self.last_pressed_key.get() { if let Some(last_pressed_key) = self.last_pressed_key.get() {
let event = WindowEvent::KeyEvent(Some(ch), last_pressed_key, KeyState::Pressed, modifiers); let event = WindowEvent::KeyEvent(Some(ch), last_pressed_key, KeyState::Pressed, modifiers);
self.event_queue.borrow_mut().push(event); self.event_queue.borrow_mut().push(event);