keymap: Concentrate special handling of BackSpace, which is implicit in Erase action
This commit is contained in:
		@ -724,19 +724,20 @@ fn create_button<H: logging::Handler>(
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
fn extract_symbol_names<'a>(actions: &'a [(&str, action::Action)])
 | 
					fn extract_symbol_names<'a>(actions: &'a [(&str, action::Action)])
 | 
				
			||||||
    -> impl Iterator<Item=&'a str>
 | 
					    -> impl Iterator<Item=String> + 'a
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    actions.iter()
 | 
					    actions.iter()
 | 
				
			||||||
        .filter_map(|(_name, act)| {
 | 
					        .filter_map(|(_name, act)| {
 | 
				
			||||||
            match act {
 | 
					            match act {
 | 
				
			||||||
                action::Action::Submit {
 | 
					                action::Action::Submit {
 | 
				
			||||||
                    text: _, keys,
 | 
					                    text: _, keys,
 | 
				
			||||||
                } => Some(keys),
 | 
					                } => Some(keys.clone()),
 | 
				
			||||||
 | 
					                action::Action::Erase => Some(vec!(action::KeySym("BackSpace".into()))),
 | 
				
			||||||
                _ => None,
 | 
					                _ => None,
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        })
 | 
					        })
 | 
				
			||||||
        .flatten()
 | 
					        .flatten()
 | 
				
			||||||
        .map(|named_keysym| named_keysym.0.as_str())
 | 
					        .map(|named_keysym| named_keysym.0)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#[cfg(test)]
 | 
					#[cfg(test)]
 | 
				
			||||||
@ -988,7 +989,7 @@ mod tests {
 | 
				
			|||||||
        )];
 | 
					        )];
 | 
				
			||||||
        assert_eq!(
 | 
					        assert_eq!(
 | 
				
			||||||
            extract_symbol_names(&actions[..]).collect::<Vec<_>>(),
 | 
					            extract_symbol_names(&actions[..]).collect::<Vec<_>>(),
 | 
				
			||||||
            Vec::<&str>::new(), //"BackSpace"], // TODO: centralize handling of BackSpace
 | 
					            vec!["BackSpace"],
 | 
				
			||||||
        );
 | 
					        );
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -79,10 +79,10 @@ impl KeyState {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/// Sorts an iterator by converting it to a Vector and back
 | 
					/// Sorts an iterator by converting it to a Vector and back
 | 
				
			||||||
fn sorted<'a, I: Iterator<Item=&'a str>>(
 | 
					fn sorted<'a, I: Iterator<Item=String>>(
 | 
				
			||||||
    iter: I
 | 
					    iter: I
 | 
				
			||||||
) -> impl Iterator<Item=&'a str> {
 | 
					) -> impl Iterator<Item=String> {
 | 
				
			||||||
    let mut v: Vec<&'a str> = iter.collect();
 | 
					    let mut v: Vec<String> = iter.collect();
 | 
				
			||||||
    v.sort();
 | 
					    v.sort();
 | 
				
			||||||
    v.into_iter()
 | 
					    v.into_iter()
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@ -90,14 +90,13 @@ fn sorted<'a, I: Iterator<Item=&'a str>>(
 | 
				
			|||||||
/// Generates a mapping where each key gets a keycode, starting from ~~8~~
 | 
					/// Generates a mapping where each key gets a keycode, starting from ~~8~~
 | 
				
			||||||
/// HACK: starting from 9, because 8 results in keycode 0,
 | 
					/// HACK: starting from 9, because 8 results in keycode 0,
 | 
				
			||||||
/// which the compositor likes to discard
 | 
					/// which the compositor likes to discard
 | 
				
			||||||
pub fn generate_keycodes<'a, C: IntoIterator<Item=&'a str>>(
 | 
					pub fn generate_keycodes<'a, C: IntoIterator<Item=String>>(
 | 
				
			||||||
    key_names: C,
 | 
					    key_names: C,
 | 
				
			||||||
) -> HashMap<String, u32> {
 | 
					) -> HashMap<String, u32> {
 | 
				
			||||||
    let special_keysyms = ["BackSpace", "Return"].iter().map(|&s| s);
 | 
					 | 
				
			||||||
    HashMap::from_iter(
 | 
					    HashMap::from_iter(
 | 
				
			||||||
        // sort to remove a source of indeterminism in keycode assignment
 | 
					        // Sort to remove a source of indeterminism in keycode assignment.
 | 
				
			||||||
        sorted(key_names.into_iter().chain(special_keysyms))
 | 
					        sorted(key_names.into_iter())
 | 
				
			||||||
            .map(|name| String::from(name))
 | 
					            .map(|name| name)
 | 
				
			||||||
            .zip(9..)
 | 
					            .zip(9..)
 | 
				
			||||||
    )
 | 
					    )
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user