Add support for labels in custom menu keymaps

pull/3958/head
Matthew Cheely 2 years ago
parent 620dfceb84
commit c92e341ee4

@ -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::<Config>(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] #[test]
fn keys_resolve_to_correct_defaults() { fn keys_resolve_to_correct_defaults() {
// From serde default // From serde default

@ -197,13 +197,22 @@ impl<'de> serde::de::Visitor<'de> for KeyTrieVisitor {
where where
M: serde::de::MapAccess<'de>, M: serde::de::MapAccess<'de>,
{ {
let mut name = "";
let mut mapping = HashMap::new(); let mut mapping = HashMap::new();
let mut order = Vec::new(); let mut order = Vec::new();
while let Some((key, value)) = map.next_entry::<KeyEvent, KeyTrie>()? {
mapping.insert(key, value); while let Some(key) = map.next_key::<&str>()? {
order.push(key); match key {
"label" => name = map.next_value::<&str>()?,
_ => {
let key_event = key.parse::<KeyEvent>().map_err(serde::de::Error::custom)?;
let key_trie = map.next_value::<KeyTrie>()?;
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)))
} }
} }

Loading…
Cancel
Save