diff --git a/helix-term/src/config.rs b/helix-term/src/config.rs index bcba8d8e1..91738f3ef 100644 --- a/helix-term/src/config.rs +++ b/helix-term/src/config.rs @@ -174,6 +174,39 @@ mod tests { ); } + #[test] + fn parsing_menus() { + use crate::keymap; + use crate::keymap::Keymap; + use helix_core::hashmap; + use helix_view::document::Mode; + + let sample_keymaps = r#" + [keys.normal] + f = { f = "file_picker", c = "wclose" } + b = { label = "buffer", b = "buffer_picker", n = "goto_next_buffer" } + "#; + + assert_eq!( + toml::from_str::(sample_keymaps).unwrap(), + Config { + keys: hashmap! { + Mode::Normal => Keymap::new(keymap!({ "Normal mode" + "f" => { "" + "f" => file_picker, + "c" => wclose, + }, + "b" => { "buffer" + "b" => buffer_picker, + "n" => goto_next_buffer, + }, + })), + }, + ..Default::default() + } + ); + } + #[test] fn keys_resolve_to_correct_defaults() { // From serde default diff --git a/helix-term/src/keymap.rs b/helix-term/src/keymap.rs index 020ecaf40..01abd7086 100644 --- a/helix-term/src/keymap.rs +++ b/helix-term/src/keymap.rs @@ -197,13 +197,22 @@ impl<'de> serde::de::Visitor<'de> for KeyTrieVisitor { where M: serde::de::MapAccess<'de>, { + let mut name = ""; let mut mapping = HashMap::new(); let mut order = Vec::new(); - while let Some((key, value)) = map.next_entry::()? { - mapping.insert(key, value); - order.push(key); + + while let Some(key) = map.next_key::<&str>()? { + match key { + "label" => name = map.next_value::<&str>()?, + _ => { + let key_event = key.parse::().map_err(serde::de::Error::custom)?; + let key_trie = map.next_value::()?; + mapping.insert(key_event, key_trie); + order.push(key_event); + } + } } - Ok(KeyTrie::Node(KeyTrieNode::new("", mapping, order))) + Ok(KeyTrie::Node(KeyTrieNode::new(name, mapping, order))) } }