From 3b0c5e993a18a2d59582855784189995c7960d6f Mon Sep 17 00:00:00 2001 From: Nehliin Date: Sat, 23 Oct 2021 15:24:19 +0200 Subject: Use deserialization fix instead --- helix-term/src/keymap.rs | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) (limited to 'helix-term/src') diff --git a/helix-term/src/keymap.rs b/helix-term/src/keymap.rs index d51204e1..5453020e 100644 --- a/helix-term/src/keymap.rs +++ b/helix-term/src/keymap.rs @@ -78,19 +78,30 @@ macro_rules! keymap { }; } -#[derive(Debug, Clone, Deserialize)] +#[derive(Debug, Clone)] pub struct KeyTrieNode { /// A label for keys coming under this node, like "Goto mode" - #[serde(skip)] name: String, - #[serde(flatten)] map: HashMap, - #[serde(skip)] order: Vec, - #[serde(skip)] pub is_sticky: bool, } +impl<'de> Deserialize<'de> for KeyTrieNode { + fn deserialize(deserializer: D) -> Result + where + D: serde::Deserializer<'de>, + { + let map = HashMap::::deserialize(deserializer)?; + let order = map.keys().copied().collect::>(); // NOTE: map.keys() has arbitrary order + Ok(Self { + map, + order, + ..Default::default() + }) + } +} + impl KeyTrieNode { pub fn new(name: &str, map: HashMap, order: Vec) -> Self { Self { @@ -118,22 +129,10 @@ impl KeyTrieNode { } self.map.insert(key, trie); } - self.set_order(); - } - - /// Sets the order of the mapping recursively since the - /// the trie can contain child nodes without order. - /// The order is missing from child nodes since it's not - /// parsed from the config.toml - fn set_order(&mut self) { - for (&key, trie) in self.map.iter_mut() { + for &key in self.map.keys() { if !self.order.contains(&key) { self.order.push(key); } - // Order must be recursively set - if let KeyTrie::Node(node) = trie { - node.set_order(); - } } } -- cgit v1.2.3-70-g09d2