summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNehliin2021-10-23 13:24:19 +0000
committerBlaž Hrastnik2021-10-28 01:22:52 +0000
commit3b0c5e993a18a2d59582855784189995c7960d6f (patch)
tree35cd3e70fc775a256e37a6c8bac90f725c686622
parent6e455fd3fb7f0ce3715ca0af72197749a2f19f57 (diff)
Use deserialization fix instead
-rw-r--r--helix-term/src/keymap.rs35
1 files changed, 17 insertions, 18 deletions
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<KeyEvent, KeyTrie>,
- #[serde(skip)]
order: Vec<KeyEvent>,
- #[serde(skip)]
pub is_sticky: bool,
}
+impl<'de> Deserialize<'de> for KeyTrieNode {
+ fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
+ where
+ D: serde::Deserializer<'de>,
+ {
+ let map = HashMap::<KeyEvent, KeyTrie>::deserialize(deserializer)?;
+ let order = map.keys().copied().collect::<Vec<_>>(); // NOTE: map.keys() has arbitrary order
+ Ok(Self {
+ map,
+ order,
+ ..Default::default()
+ })
+ }
+}
+
impl KeyTrieNode {
pub fn new(name: &str, map: HashMap<KeyEvent, KeyTrie>, order: Vec<KeyEvent>) -> 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();
- }
}
}