Change the dispatch in TextInput::handle_keydown_aux match on enum values instead of strings.

This commit is contained in:
Avi Weinstock 2015-05-03 13:07:45 -04:00
parent 29f8306089
commit 0587717944
2 changed files with 203 additions and 193 deletions

View file

@ -109,16 +109,11 @@ impl KeyboardEvent {
pub fn Constructor(global: GlobalRef, pub fn Constructor(global: GlobalRef,
type_: DOMString, type_: DOMString,
init: &KeyboardEventBinding::KeyboardEventInit) -> Fallible<Temporary<KeyboardEvent>> { init: &KeyboardEventBinding::KeyboardEventInit) -> Fallible<Temporary<KeyboardEvent>> {
let key = if let Some((key, _)) = key_from_string(init.key.as_slice()) {
Some(key)
} else {
None
};
let event = KeyboardEvent::new(global.as_window(), type_, let event = KeyboardEvent::new(global.as_window(), type_,
init.parent.parent.parent.bubbles, init.parent.parent.parent.bubbles,
init.parent.parent.parent.cancelable, init.parent.parent.parent.cancelable,
init.parent.parent.view.r(), init.parent.parent.view.r(),
init.parent.parent.detail, key, init.parent.parent.detail, key_from_string(&init.key, init.location),
init.key.clone(), init.code.clone(), init.location, init.key.clone(), init.code.clone(), init.location,
init.repeat, init.isComposing, init.parent.ctrlKey, init.repeat, init.isComposing, init.parent.ctrlKey,
init.parent.altKey, init.parent.shiftKey, init.parent.metaKey, init.parent.altKey, init.parent.shiftKey, init.parent.metaKey,
@ -341,175 +336,173 @@ pub fn key_value(key: Key, mods: KeyModifiers) -> &'static str {
} }
} }
pub fn key_from_string(key_string: &str) -> Option<(Key, KeyModifiers)> { fn key_from_string(key_string: &str, location: u32) -> Option<Key> {
match key_string { match key_string {
" " => Some((Key::Space, KeyModifiers::empty())), " " => Some(Key::Space),
"\"" => Some((Key::Apostrophe, SHIFT)), "\"" => Some(Key::Apostrophe),
"'" => Some((Key::Apostrophe, KeyModifiers::empty())), "'" => Some(Key::Apostrophe),
"<" => Some((Key::Comma, SHIFT)), "<" => Some(Key::Comma),
"," => Some((Key::Comma, KeyModifiers::empty())), "," => Some(Key::Comma),
"_" => Some((Key::Minus, SHIFT)), "_" => Some(Key::Minus),
"-" => Some((Key::Minus, KeyModifiers::empty())), "-" if location == KeyboardEventConstants::DOM_KEY_LOCATION_STANDARD => Some(Key::Minus),
">" => Some((Key::Period, SHIFT)), ">" => Some(Key::Period),
"." => Some((Key::Period, KeyModifiers::empty())), "." if location == KeyboardEventConstants::DOM_KEY_LOCATION_STANDARD => Some(Key::Period),
"?" => Some((Key::Slash, SHIFT)), "?" => Some(Key::Slash),
"/" => Some((Key::Slash, KeyModifiers::empty())), "/" if location == KeyboardEventConstants::DOM_KEY_LOCATION_STANDARD => Some(Key::Slash),
"~" => Some((Key::GraveAccent, SHIFT)), "~" => Some(Key::GraveAccent),
"`" => Some((Key::GraveAccent, KeyModifiers::empty())), "`" => Some(Key::GraveAccent),
")" => Some((Key::Num0, SHIFT)), ")" => Some(Key::Num0),
"0" => Some((Key::Num0, KeyModifiers::empty())), "0" if location == KeyboardEventConstants::DOM_KEY_LOCATION_STANDARD => Some(Key::Num0),
"!" => Some((Key::Num1, SHIFT)), "!" => Some(Key::Num1),
"1" => Some((Key::Num1, KeyModifiers::empty())), "1" if location == KeyboardEventConstants::DOM_KEY_LOCATION_STANDARD => Some(Key::Num1),
"@" => Some((Key::Num2, SHIFT)), "@" => Some(Key::Num2),
"2" => Some((Key::Num2, KeyModifiers::empty())), "2" if location == KeyboardEventConstants::DOM_KEY_LOCATION_STANDARD => Some(Key::Num2),
"#" => Some((Key::Num3, SHIFT)), "#" => Some(Key::Num3),
"3" => Some((Key::Num3, KeyModifiers::empty())), "3" if location == KeyboardEventConstants::DOM_KEY_LOCATION_STANDARD => Some(Key::Num3),
"$" => Some((Key::Num4, SHIFT)), "$" => Some(Key::Num4),
"4" => Some((Key::Num4, KeyModifiers::empty())), "4" if location == KeyboardEventConstants::DOM_KEY_LOCATION_STANDARD => Some(Key::Num4),
"%" => Some((Key::Num5, SHIFT)), "%" => Some(Key::Num5),
"5" => Some((Key::Num5, KeyModifiers::empty())), "5" if location == KeyboardEventConstants::DOM_KEY_LOCATION_STANDARD => Some(Key::Num5),
"^" => Some((Key::Num6, SHIFT)), "^" => Some(Key::Num6),
"6" => Some((Key::Num6, KeyModifiers::empty())), "6" if location == KeyboardEventConstants::DOM_KEY_LOCATION_STANDARD => Some(Key::Num6),
"&" => Some((Key::Num7, SHIFT)), "&" => Some(Key::Num7),
"7" => Some((Key::Num7, KeyModifiers::empty())), "7" if location == KeyboardEventConstants::DOM_KEY_LOCATION_STANDARD => Some(Key::Num7),
"*" => Some((Key::Num8, SHIFT)), "*" if location == KeyboardEventConstants::DOM_KEY_LOCATION_STANDARD => Some(Key::Num8),
"8" => Some((Key::Num8, KeyModifiers::empty())), "8" if location == KeyboardEventConstants::DOM_KEY_LOCATION_STANDARD => Some(Key::Num8),
"(" => Some((Key::Num9, SHIFT)), "(" => Some(Key::Num9),
"9" => Some((Key::Num9, KeyModifiers::empty())), "9" if location == KeyboardEventConstants::DOM_KEY_LOCATION_STANDARD => Some(Key::Num9),
":" => Some((Key::Semicolon, SHIFT)), ":" => Some(Key::Semicolon),
";" => Some((Key::Semicolon, KeyModifiers::empty())), ";" => Some(Key::Semicolon),
"+" => Some((Key::Equal, SHIFT)), "+" if location == KeyboardEventConstants::DOM_KEY_LOCATION_STANDARD => Some(Key::Equal),
"=" => Some((Key::Equal, KeyModifiers::empty())), "=" if location == KeyboardEventConstants::DOM_KEY_LOCATION_STANDARD => Some(Key::Equal),
"A" => Some((Key::A, SHIFT)), "A" => Some(Key::A),
"a" => Some((Key::A, KeyModifiers::empty())), "a" => Some(Key::A),
"B" => Some((Key::B, SHIFT)), "B" => Some(Key::B),
"b" => Some((Key::B, KeyModifiers::empty())), "b" => Some(Key::B),
"C" => Some((Key::C, SHIFT)), "C" => Some(Key::C),
"c" => Some((Key::C, KeyModifiers::empty())), "c" => Some(Key::C),
"D" => Some((Key::D, SHIFT)), "D" => Some(Key::D),
"d" => Some((Key::D, KeyModifiers::empty())), "d" => Some(Key::D),
"E" => Some((Key::E, SHIFT)), "E" => Some(Key::E),
"e" => Some((Key::E, KeyModifiers::empty())), "e" => Some(Key::E),
"F" => Some((Key::F, SHIFT)), "F" => Some(Key::F),
"f" => Some((Key::F, KeyModifiers::empty())), "f" => Some(Key::F),
"G" => Some((Key::G, SHIFT)), "G" => Some(Key::G),
"g" => Some((Key::G, KeyModifiers::empty())), "g" => Some(Key::G),
"H" => Some((Key::H, SHIFT)), "H" => Some(Key::H),
"h" => Some((Key::H, KeyModifiers::empty())), "h" => Some(Key::H),
"I" => Some((Key::I, SHIFT)), "I" => Some(Key::I),
"i" => Some((Key::I, KeyModifiers::empty())), "i" => Some(Key::I),
"J" => Some((Key::J, SHIFT)), "J" => Some(Key::J),
"j" => Some((Key::J, KeyModifiers::empty())), "j" => Some(Key::J),
"K" => Some((Key::K, SHIFT)), "K" => Some(Key::K),
"k" => Some((Key::K, KeyModifiers::empty())), "k" => Some(Key::K),
"L" => Some((Key::L, SHIFT)), "L" => Some(Key::L),
"l" => Some((Key::L, KeyModifiers::empty())), "l" => Some(Key::L),
"M" => Some((Key::M, SHIFT)), "M" => Some(Key::M),
"m" => Some((Key::M, KeyModifiers::empty())), "m" => Some(Key::M),
"N" => Some((Key::N, SHIFT)), "N" => Some(Key::N),
"n" => Some((Key::N, KeyModifiers::empty())), "n" => Some(Key::N),
"O" => Some((Key::O, SHIFT)), "O" => Some(Key::O),
"o" => Some((Key::O, KeyModifiers::empty())), "o" => Some(Key::O),
"P" => Some((Key::P, SHIFT)), "P" => Some(Key::P),
"p" => Some((Key::P, KeyModifiers::empty())), "p" => Some(Key::P),
"Q" => Some((Key::Q, SHIFT)), "Q" => Some(Key::Q),
"q" => Some((Key::Q, KeyModifiers::empty())), "q" => Some(Key::Q),
"R" => Some((Key::R, SHIFT)), "R" => Some(Key::R),
"r" => Some((Key::R, KeyModifiers::empty())), "r" => Some(Key::R),
"S" => Some((Key::S, SHIFT)), "S" => Some(Key::S),
"s" => Some((Key::S, KeyModifiers::empty())), "s" => Some(Key::S),
"T" => Some((Key::T, SHIFT)), "T" => Some(Key::T),
"t" => Some((Key::T, KeyModifiers::empty())), "t" => Some(Key::T),
"U" => Some((Key::U, SHIFT)), "U" => Some(Key::U),
"u" => Some((Key::U, KeyModifiers::empty())), "u" => Some(Key::U),
"V" => Some((Key::V, SHIFT)), "V" => Some(Key::V),
"v" => Some((Key::V, KeyModifiers::empty())), "v" => Some(Key::V),
"W" => Some((Key::W, SHIFT)), "W" => Some(Key::W),
"w" => Some((Key::W, KeyModifiers::empty())), "w" => Some(Key::W),
"X" => Some((Key::X, SHIFT)), "X" => Some(Key::X),
"x" => Some((Key::X, KeyModifiers::empty())), "x" => Some(Key::X),
"Y" => Some((Key::Y, SHIFT)), "Y" => Some(Key::Y),
"y" => Some((Key::Y, KeyModifiers::empty())), "y" => Some(Key::Y),
"Z" => Some((Key::Z, SHIFT)), "Z" => Some(Key::Z),
"z" => Some((Key::Z, KeyModifiers::empty())), "z" => Some(Key::Z),
"{" => Some((Key::LeftBracket, SHIFT)), "{" => Some(Key::LeftBracket),
"[" => Some((Key::LeftBracket, KeyModifiers::empty())), "[" => Some(Key::LeftBracket),
"|" => Some((Key::Backslash, SHIFT)), "|" => Some(Key::Backslash),
"\\" => Some((Key::Backslash, KeyModifiers::empty())), "\\" => Some(Key::Backslash),
"}" => Some((Key::RightBracket, SHIFT)), "}" => Some(Key::RightBracket),
"]" => Some((Key::RightBracket, KeyModifiers::empty())), "]" => Some(Key::RightBracket),
"Unidentified" => Some((Key::World1, KeyModifiers::empty())), "Escape" => Some(Key::Escape),
/*"Unidentified" => Some((Key::World2, KeyModifiers::empty())),*/ "Enter" if location == KeyboardEventConstants::DOM_KEY_LOCATION_STANDARD => Some(Key::Enter),
"Escape" => Some((Key::Escape, KeyModifiers::empty())), "Tab" => Some(Key::Tab),
"Enter" => Some((Key::Enter, KeyModifiers::empty())), "Backspace" => Some(Key::Backspace),
"Tab" => Some((Key::Tab, KeyModifiers::empty())), "Insert" => Some(Key::Insert),
"Backspace" => Some((Key::Backspace, KeyModifiers::empty())), "Delete" => Some(Key::Delete),
"Insert" => Some((Key::Insert, KeyModifiers::empty())), "ArrowRight" => Some(Key::Right),
"Delete" => Some((Key::Delete, KeyModifiers::empty())), "ArrowLeft" => Some(Key::Left),
"ArrowRight" => Some((Key::Right, KeyModifiers::empty())), "ArrowDown" => Some(Key::Down),
"ArrowLeft" => Some((Key::Left, KeyModifiers::empty())), "ArrowUp" => Some(Key::Up),
"ArrowDown" => Some((Key::Down, KeyModifiers::empty())), "PageUp" => Some(Key::PageUp),
"ArrowUp" => Some((Key::Up, KeyModifiers::empty())), "PageDown" => Some(Key::PageDown),
"PageUp" => Some((Key::PageUp, KeyModifiers::empty())), "Home" => Some(Key::Home),
"PageDown" => Some((Key::PageDown, KeyModifiers::empty())), "End" => Some(Key::End),
"Home" => Some((Key::Home, KeyModifiers::empty())), "CapsLock" => Some(Key::CapsLock),
"End" => Some((Key::End, KeyModifiers::empty())), "ScrollLock" => Some(Key::ScrollLock),
"CapsLock" => Some((Key::CapsLock, KeyModifiers::empty())), "NumLock" => Some(Key::NumLock),
"ScrollLock" => Some((Key::ScrollLock, KeyModifiers::empty())), "PrintScreen" => Some(Key::PrintScreen),
"NumLock" => Some((Key::NumLock, KeyModifiers::empty())), "Pause" => Some(Key::Pause),
"PrintScreen" => Some((Key::PrintScreen, KeyModifiers::empty())), "F1" => Some(Key::F1),
"Pause" => Some((Key::Pause, KeyModifiers::empty())), "F2" => Some(Key::F2),
"F1" => Some((Key::F1, KeyModifiers::empty())), "F3" => Some(Key::F3),
"F2" => Some((Key::F2, KeyModifiers::empty())), "F4" => Some(Key::F4),
"F3" => Some((Key::F3, KeyModifiers::empty())), "F5" => Some(Key::F5),
"F4" => Some((Key::F4, KeyModifiers::empty())), "F6" => Some(Key::F6),
"F5" => Some((Key::F5, KeyModifiers::empty())), "F7" => Some(Key::F7),
"F6" => Some((Key::F6, KeyModifiers::empty())), "F8" => Some(Key::F8),
"F7" => Some((Key::F7, KeyModifiers::empty())), "F9" => Some(Key::F9),
"F8" => Some((Key::F8, KeyModifiers::empty())), "F10" => Some(Key::F10),
"F9" => Some((Key::F9, KeyModifiers::empty())), "F11" => Some(Key::F11),
"F10" => Some((Key::F10, KeyModifiers::empty())), "F12" => Some(Key::F12),
"F11" => Some((Key::F11, KeyModifiers::empty())), "F13" => Some(Key::F13),
"F12" => Some((Key::F12, KeyModifiers::empty())), "F14" => Some(Key::F14),
"F13" => Some((Key::F13, KeyModifiers::empty())), "F15" => Some(Key::F15),
"F14" => Some((Key::F14, KeyModifiers::empty())), "F16" => Some(Key::F16),
"F15" => Some((Key::F15, KeyModifiers::empty())), "F17" => Some(Key::F17),
"F16" => Some((Key::F16, KeyModifiers::empty())), "F18" => Some(Key::F18),
"F17" => Some((Key::F17, KeyModifiers::empty())), "F19" => Some(Key::F19),
"F18" => Some((Key::F18, KeyModifiers::empty())), "F20" => Some(Key::F20),
"F19" => Some((Key::F19, KeyModifiers::empty())), "F21" => Some(Key::F21),
"F20" => Some((Key::F20, KeyModifiers::empty())), "F22" => Some(Key::F22),
"F21" => Some((Key::F21, KeyModifiers::empty())), "F23" => Some(Key::F23),
"F22" => Some((Key::F22, KeyModifiers::empty())), "F24" => Some(Key::F24),
"F23" => Some((Key::F23, KeyModifiers::empty())), "F25" => Some(Key::F25),
"F24" => Some((Key::F24, KeyModifiers::empty())), "0" if location == KeyboardEventConstants::DOM_KEY_LOCATION_NUMPAD => Some(Key::Kp0),
"F25" => Some((Key::F25, KeyModifiers::empty())), "1" if location == KeyboardEventConstants::DOM_KEY_LOCATION_NUMPAD => Some(Key::Kp1),
/*"0" => Some((Key::Kp0, KeyModifiers::empty())), "2" if location == KeyboardEventConstants::DOM_KEY_LOCATION_NUMPAD => Some(Key::Kp2),
"1" => Some((Key::Kp1, KeyModifiers::empty())), "3" if location == KeyboardEventConstants::DOM_KEY_LOCATION_NUMPAD => Some(Key::Kp3),
"2" => Some((Key::Kp2, KeyModifiers::empty())), "4" if location == KeyboardEventConstants::DOM_KEY_LOCATION_NUMPAD => Some(Key::Kp4),
"3" => Some((Key::Kp3, KeyModifiers::empty())), "5" if location == KeyboardEventConstants::DOM_KEY_LOCATION_NUMPAD => Some(Key::Kp5),
"4" => Some((Key::Kp4, KeyModifiers::empty())), "6" if location == KeyboardEventConstants::DOM_KEY_LOCATION_NUMPAD => Some(Key::Kp6),
"5" => Some((Key::Kp5, KeyModifiers::empty())), "7" if location == KeyboardEventConstants::DOM_KEY_LOCATION_NUMPAD => Some(Key::Kp7),
"6" => Some((Key::Kp6, KeyModifiers::empty())), "8" if location == KeyboardEventConstants::DOM_KEY_LOCATION_NUMPAD => Some(Key::Kp8),
"7" => Some((Key::Kp7, KeyModifiers::empty())), "9" if location == KeyboardEventConstants::DOM_KEY_LOCATION_NUMPAD => Some(Key::Kp9),
"8" => Some((Key::Kp8, KeyModifiers::empty())), "." if location == KeyboardEventConstants::DOM_KEY_LOCATION_NUMPAD => Some(Key::KpDecimal),
"9" => Some((Key::Kp9, KeyModifiers::empty())), "/" if location == KeyboardEventConstants::DOM_KEY_LOCATION_NUMPAD => Some(Key::KpDivide),
"." => Some((Key::KpDecimal, KeyModifiers::empty())), "*" if location == KeyboardEventConstants::DOM_KEY_LOCATION_NUMPAD => Some(Key::KpMultiply),
"/" => Some((Key::KpDivide, KeyModifiers::empty())), "-" if location == KeyboardEventConstants::DOM_KEY_LOCATION_NUMPAD => Some(Key::KpSubtract),
"*" => Some((Key::KpMultiply, KeyModifiers::empty())), "+" if location == KeyboardEventConstants::DOM_KEY_LOCATION_NUMPAD => Some(Key::KpAdd),
"-" => Some((Key::KpSubtract, KeyModifiers::empty())), "Enter" if location == KeyboardEventConstants::DOM_KEY_LOCATION_NUMPAD => Some(Key::KpEnter),
"+" => Some((Key::KpAdd, KeyModifiers::empty())), "=" if location == KeyboardEventConstants::DOM_KEY_LOCATION_NUMPAD => Some(Key::KpEqual),
"Enter" => Some((Key::KpEnter, KeyModifiers::empty())), "Shift" if location == KeyboardEventConstants::DOM_KEY_LOCATION_LEFT => Some(Key::LeftShift),
"=" => Some((Key::KpEqual, KeyModifiers::empty())),*/ "Control" if location == KeyboardEventConstants::DOM_KEY_LOCATION_LEFT => Some(Key::LeftControl),
"Shift" => Some((Key::LeftShift, SHIFT)), "Alt" if location == KeyboardEventConstants::DOM_KEY_LOCATION_LEFT => Some(Key::LeftAlt),
"Control" => Some((Key::LeftControl, CONTROL)), "Super" if location == KeyboardEventConstants::DOM_KEY_LOCATION_LEFT => Some(Key::LeftSuper),
"Alt" => Some((Key::LeftAlt, ALT)), "Shift" if location == KeyboardEventConstants::DOM_KEY_LOCATION_RIGHT => Some(Key::RightShift),
"Super" => Some((Key::LeftSuper, SUPER)), "Control" if location == KeyboardEventConstants::DOM_KEY_LOCATION_RIGHT => Some(Key::RightControl),
/*"Shift" => Some((Key::RightShift, SHIFT)), "Alt" if location == KeyboardEventConstants::DOM_KEY_LOCATION_RIGHT => Some(Key::RightAlt),
"Control" => Some((Key::RightControl, CONTROL)), "Super" if location == KeyboardEventConstants::DOM_KEY_LOCATION_RIGHT => Some(Key::RightSuper),
"Alt" => Some((Key::RightAlt, ALT)), "ContextMenu" => Some(Key::Menu),
"Super" => Some((Key::RightSuper, SUPER)),*/
"ContextMenu" => Some((Key::Menu, KeyModifiers::empty())),
_ => None _ => None
} }
} }

View file

@ -88,6 +88,24 @@ fn is_control_key(mods: KeyModifiers) -> bool {
mods.contains(CONTROL) && !mods.contains(SUPER | ALT) mods.contains(CONTROL) && !mods.contains(SUPER | ALT)
} }
fn is_printable_key(key: Key) -> bool {
match key {
Key::Space | Key::Apostrophe | Key::Comma | Key::Minus |
Key::Period | Key::Slash | Key::GraveAccent | Key::Num0 |
Key::Num1 | Key::Num2 | Key::Num3 | Key::Num4 | Key::Num5 |
Key::Num6 | Key::Num7 | Key::Num8 | Key::Num9 | Key::Semicolon |
Key::Equal | Key::A | Key::B | Key::C | Key::D | Key::E | Key::F |
Key::G | Key::H | Key::I | Key::J | Key::K | Key::L | Key::M | Key::N |
Key::O | Key::P | Key::Q | Key::R | Key::S | Key::T | Key::U | Key::V |
Key::W | Key::X | Key::Y | Key::Z | Key::LeftBracket | Key::Backslash |
Key::RightBracket | Key::Kp0 | Key::Kp1 | Key::Kp2 | Key::Kp3 |
Key::Kp4 | Key::Kp5 | Key::Kp6 | Key::Kp7 | Key::Kp8 | Key::Kp9 |
Key::KpDecimal | Key::KpDivide | Key::KpMultiply | Key::KpSubtract |
Key::KpAdd | Key::KpEqual => true,
_ => false,
}
}
impl<T: ClipboardProvider> TextInput<T> { impl<T: ClipboardProvider> TextInput<T> {
/// Instantiate a new text input control /// Instantiate a new text input control
pub fn new(lines: Lines, initial: DOMString, clipboard_provider: T) -> TextInput<T> { pub fn new(lines: Lines, initial: DOMString, clipboard_provider: T) -> TextInput<T> {
@ -291,67 +309,66 @@ impl<T: ClipboardProvider> TextInput<T> {
} }
pub fn handle_keydown_aux(&mut self, key: Key, mods: KeyModifiers) -> KeyReaction { pub fn handle_keydown_aux(&mut self, key: Key, mods: KeyModifiers) -> KeyReaction {
let maybe_select = if mods.contains(SHIFT) { Selection::Selected } else { Selection::NotSelected }; let maybe_select = if mods.contains(SHIFT) { Selection::Selected } else { Selection::NotSelected };
match key_value(key, mods) { match key {
"a" if is_control_key(mods) => { Key::A if is_control_key(mods) => {
self.select_all(); self.select_all();
KeyReaction::Nothing KeyReaction::Nothing
}, },
"v" if is_control_key(mods) => { Key::V if is_control_key(mods) => {
let contents = self.clipboard_provider.get_clipboard_contents(); let contents = self.clipboard_provider.get_clipboard_contents();
self.insert_string(&contents); self.insert_string(&contents);
KeyReaction::DispatchInput KeyReaction::DispatchInput
}, },
// printable characters have single-character key values _ if is_printable_key(key) => {
c if c.len() == 1 => { self.insert_string(key_value(key, mods));
self.insert_char(c.chars().next().unwrap());
KeyReaction::DispatchInput KeyReaction::DispatchInput
} }
"Space" => { Key::Space => {
self.insert_char(' '); self.insert_char(' ');
KeyReaction::DispatchInput KeyReaction::DispatchInput
} }
"Delete" => { Key::Delete => {
self.delete_char(DeleteDir::Forward); self.delete_char(DeleteDir::Forward);
KeyReaction::DispatchInput KeyReaction::DispatchInput
} }
"Backspace" => { Key::Backspace => {
self.delete_char(DeleteDir::Backward); self.delete_char(DeleteDir::Backward);
KeyReaction::DispatchInput KeyReaction::DispatchInput
} }
"ArrowLeft" => { Key::Left => {
self.adjust_horizontal(-1, maybe_select); self.adjust_horizontal(-1, maybe_select);
KeyReaction::Nothing KeyReaction::Nothing
} }
"ArrowRight" => { Key::Right => {
self.adjust_horizontal(1, maybe_select); self.adjust_horizontal(1, maybe_select);
KeyReaction::Nothing KeyReaction::Nothing
} }
"ArrowUp" => { Key::Up => {
self.adjust_vertical(-1, maybe_select); self.adjust_vertical(-1, maybe_select);
KeyReaction::Nothing KeyReaction::Nothing
} }
"ArrowDown" => { Key::Down => {
self.adjust_vertical(1, maybe_select); self.adjust_vertical(1, maybe_select);
KeyReaction::Nothing KeyReaction::Nothing
} }
"Enter" => self.handle_return(), Key::Enter | Key::KpEnter => self.handle_return(),
"Home" => { Key::Home => {
self.edit_point.index = 0; self.edit_point.index = 0;
KeyReaction::Nothing KeyReaction::Nothing
} }
"End" => { Key::End => {
self.edit_point.index = self.current_line_length(); self.edit_point.index = self.current_line_length();
KeyReaction::Nothing KeyReaction::Nothing
} }
"PageUp" => { Key::PageUp => {
self.adjust_vertical(-28, maybe_select); self.adjust_vertical(-28, maybe_select);
KeyReaction::Nothing KeyReaction::Nothing
} }
"PageDown" => { Key::PageDown => {
self.adjust_vertical(28, maybe_select); self.adjust_vertical(28, maybe_select);
KeyReaction::Nothing KeyReaction::Nothing
} }
"Tab" => KeyReaction::TriggerDefaultAction, Key::Tab => KeyReaction::TriggerDefaultAction,
_ => KeyReaction::Nothing, _ => KeyReaction::Nothing,
} }
} }