diff --git a/rm-config/src/keymap/actions/general.rs b/rm-config/src/keymap/actions/general.rs index d659fde..dad4414 100644 --- a/rm-config/src/keymap/actions/general.rs +++ b/rm-config/src/keymap/actions/general.rs @@ -36,25 +36,6 @@ pub enum GeneralActionMergable { } impl UserAction for GeneralAction { - fn is_mergable_with(&self, other: &GeneralAction) -> bool { - let other = *other; - match self { - GeneralAction::SwitchToTorrents => other == Self::SwitchToSearch, - GeneralAction::SwitchToSearch => other == Self::SwitchToTorrents, - GeneralAction::Left => other == Self::Right, - GeneralAction::Right => other == Self::Left, - GeneralAction::Down => other == Self::Up, - GeneralAction::Up => other == Self::Down, - GeneralAction::ScrollPageDown => other == Self::ScrollPageUp, - GeneralAction::ScrollPageUp => other == Self::ScrollPageDown, - GeneralAction::GoToBeginning => other == Self::GoToEnd, - GeneralAction::GoToEnd => other == Self::GoToBeginning, - GeneralAction::MoveToColumnLeft => other == Self::MoveToColumnRight, - GeneralAction::MoveToColumnRight => other == Self::MoveToColumnLeft, - _ => false, - } - } - fn desc(&self) -> &'static str { match self { GeneralAction::ShowHelp => "toggle help", @@ -80,7 +61,7 @@ impl UserAction for GeneralAction { } } - fn merged_desc(&self, other: &GeneralAction) -> Option<&'static str> { + fn merge_desc_with(&self, other: &GeneralAction) -> Option<&'static str> { match (&self, other) { (Self::Left, Self::Right) => Some("switch to tab left / right"), (Self::Right, Self::Left) => Some("switch to tab right / left"), diff --git a/rm-config/src/keymap/actions/mod.rs b/rm-config/src/keymap/actions/mod.rs index f4e2160..eb7f88e 100644 --- a/rm-config/src/keymap/actions/mod.rs +++ b/rm-config/src/keymap/actions/mod.rs @@ -6,12 +6,8 @@ pub mod torrents_tab; pub trait UserAction: Into { fn desc(&self) -> &'static str; - fn merged_desc(&self, other: &Self) -> Option<&'static str> { + fn merge_desc_with(&self, other: &Self) -> Option<&'static str> { let _ = other; None } - fn is_mergable_with(&self, other: &Self) -> bool { - let _ = other; - false - } } diff --git a/rm-config/src/keymap/mod.rs b/rm-config/src/keymap/mod.rs index 3469305..228e290 100644 --- a/rm-config/src/keymap/mod.rs +++ b/rm-config/src/keymap/mod.rs @@ -42,7 +42,7 @@ pub struct KeybindsHolder + UserAction> { pub keybindings: Vec>, } -impl + Ord + UserAction> KeybindsHolder { +impl KeybindsHolder { const KEYS_DELIMITER: &'static str = ", "; pub fn get_help_repr(&self) -> Vec<(String, &'static str)> { @@ -73,7 +73,7 @@ impl + Ord + UserAction> KeybindsHolder { } if let Some((next_action, next_keycodes)) = new_keys.get(idx + 1) { - if action.is_mergable_with(next_action) { + if let Some(merged_desc) = action.merge_desc_with(next_action) { skip_next_loop = true; let keys = format!( "{} / {}", @@ -81,11 +81,7 @@ impl + Ord + UserAction> KeybindsHolder { next_keycodes.join(Self::KEYS_DELIMITER) ); - let desc = action - .merged_desc(next_action) - .expect("keys checked for mergability before"); - - res.push((keys, desc)); + res.push((keys, merged_desc)); continue; } } @@ -100,7 +96,7 @@ impl + Ord + UserAction> KeybindsHolder { } #[derive(Serialize, Clone)] -pub struct Keybinding { +pub struct Keybinding { pub on: KeyCode, #[serde(default)] pub modifier: KeyModifier, @@ -108,7 +104,7 @@ pub struct Keybinding { pub show_in_help: bool, } -impl + UserAction> Keybinding { +impl Keybinding { pub fn keycode_string(&self) -> String { let key = match self.on { KeyCode::Backspace => "Backspace".into(), @@ -154,7 +150,7 @@ impl + UserAction> Keybinding { } } -impl Keybinding { +impl Keybinding { fn new(on: KeyCode, action: T, modifier: Option, show_in_help: bool) -> Self { Self { on, @@ -165,7 +161,7 @@ impl Keybinding { } } -impl<'de, T: Deserialize<'de> + UserAction> Deserialize<'de> for Keybinding { +impl<'de, T: Deserialize<'de>> Deserialize<'de> for Keybinding { fn deserialize(deserializer: D) -> std::prelude::v1::Result where D: serde::Deserializer<'de>, @@ -183,7 +179,7 @@ impl<'de, T: Deserialize<'de> + UserAction> Deserialize<'de> for Keybinding { phantom: PhantomData, } - impl<'de, T: Deserialize<'de> + UserAction> Visitor<'de> for KeybindingVisitor { + impl<'de, T: Deserialize<'de>> Visitor<'de> for KeybindingVisitor { type Value = Keybinding; fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result { @@ -398,7 +394,6 @@ impl KeymapConfig { } else { Some(keys) } - } fn populate_hashmap(&mut self) {