Move key binding groups to config crate
This commit is contained in:
parent
5a0efd69e4
commit
e1c3a463b2
7 changed files with 33 additions and 7 deletions
|
|
@ -173,11 +173,35 @@ impl<'de> Deserialize<'de> for KeyPress {
|
|||
pub struct KeyBinding(Vec<KeyPress>);
|
||||
|
||||
impl KeyBinding {
|
||||
pub fn new() -> Self {
|
||||
Self(vec![])
|
||||
}
|
||||
|
||||
pub fn with_key(self, key: &str) -> Result<Self, ParseKeysError> {
|
||||
self.with_keys([key])
|
||||
}
|
||||
|
||||
pub fn with_keys<'a, I>(mut self, keys: I) -> Result<Self, ParseKeysError>
|
||||
where
|
||||
I: IntoIterator<Item = &'a str>,
|
||||
{
|
||||
for key in keys {
|
||||
self.0.push(key.parse()?);
|
||||
}
|
||||
Ok(self)
|
||||
}
|
||||
|
||||
pub fn matches(&self, event: KeyEvent) -> bool {
|
||||
self.0.iter().any(|kp| kp.matches(event))
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for KeyBinding {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
impl Serialize for KeyBinding {
|
||||
fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
|
||||
if self.0.len() == 1 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue