Skip to content

Commit

Permalink
fix(keyevent): do not emit default ignorable codepoint
Browse files Browse the repository at this point in the history
  • Loading branch information
kwonoj committed Mar 21, 2018
1 parent fd60007 commit da586d0
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions ports/servo/glutin_app/window.rs
Expand Up @@ -346,8 +346,32 @@ impl Window {
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) {
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() {
let event = WindowEvent::KeyEvent(Some(ch), last_pressed_key, KeyState::Pressed, modifiers);
self.event_queue.borrow_mut().push(event);
Expand Down

0 comments on commit da586d0

Please sign in to comment.