From 88d3a45083eafd1587fcacceaf7bf7e1f4775482 Mon Sep 17 00:00:00 2001 From: Dorota Czaplejewicz Date: Mon, 28 Sep 2020 18:37:00 +0000 Subject: [PATCH] keymap: Concentrate special handling of BackSpace, which is implicit in Erase action --- src/data.rs | 9 +++++---- src/keyboard.rs | 15 +++++++-------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/data.rs b/src/data.rs index 94b6faa3..fbd918d2 100644 --- a/src/data.rs +++ b/src/data.rs @@ -724,19 +724,20 @@ fn create_button( } fn extract_symbol_names<'a>(actions: &'a [(&str, action::Action)]) - -> impl Iterator + -> impl Iterator + 'a { actions.iter() .filter_map(|(_name, act)| { match act { action::Action::Submit { text: _, keys, - } => Some(keys), + } => Some(keys.clone()), + action::Action::Erase => Some(vec!(action::KeySym("BackSpace".into()))), _ => None, } }) .flatten() - .map(|named_keysym| named_keysym.0.as_str()) + .map(|named_keysym| named_keysym.0) } #[cfg(test)] @@ -988,7 +989,7 @@ mod tests { )]; assert_eq!( extract_symbol_names(&actions[..]).collect::>(), - Vec::<&str>::new(), //"BackSpace"], // TODO: centralize handling of BackSpace + vec!["BackSpace"], ); } diff --git a/src/keyboard.rs b/src/keyboard.rs index 0541f2b6..d1946227 100644 --- a/src/keyboard.rs +++ b/src/keyboard.rs @@ -79,10 +79,10 @@ impl KeyState { } /// Sorts an iterator by converting it to a Vector and back -fn sorted<'a, I: Iterator>( +fn sorted<'a, I: Iterator>( iter: I -) -> impl Iterator { - let mut v: Vec<&'a str> = iter.collect(); +) -> impl Iterator { + let mut v: Vec = iter.collect(); v.sort(); v.into_iter() } @@ -90,14 +90,13 @@ fn sorted<'a, I: Iterator>( /// Generates a mapping where each key gets a keycode, starting from ~~8~~ /// HACK: starting from 9, because 8 results in keycode 0, /// which the compositor likes to discard -pub fn generate_keycodes<'a, C: IntoIterator>( +pub fn generate_keycodes<'a, C: IntoIterator>( key_names: C, ) -> HashMap { - let special_keysyms = ["BackSpace", "Return"].iter().map(|&s| s); HashMap::from_iter( - // sort to remove a source of indeterminism in keycode assignment - sorted(key_names.into_iter().chain(special_keysyms)) - .map(|name| String::from(name)) + // Sort to remove a source of indeterminism in keycode assignment. + sorted(key_names.into_iter()) + .map(|name| name) .zip(9..) ) }