diff --git a/helix-term/src/config.rs b/helix-term/src/config.rs index 92b4fb8565ce..0363311c4d5a 100644 --- a/helix-term/src/config.rs +++ b/helix-term/src/config.rs @@ -187,21 +187,27 @@ mod tests { b = { label = "buffer", b = "buffer_picker", n = "goto_next_buffer" } "#; + let mut keys = keymap::default(); + merge_keys( + &mut keys, + hashmap! { + Mode::Normal => Keymap::new(keymap!({ "Normal mode" + "f" => { "" + "f" => file_picker, + "c" => wclose, + }, + "b" => { "buffer" + "b" => buffer_picker, + "n" => goto_next_buffer, + }, + })), + }, + ); + assert_eq!( - toml::from_str::(sample_keymaps).unwrap(), + Config::load_test(sample_keymaps), 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, - }, - })), - }, + keys, ..Default::default() } ); @@ -221,7 +227,7 @@ mod tests { c = ":buffer-close" "#; - let config = toml::from_str::(sample_keymaps).unwrap(); + let config = Config::load_test(sample_keymaps); let tree = config.keys.get(&Mode::Normal).unwrap().root(); diff --git a/helix-term/src/keymap.rs b/helix-term/src/keymap.rs index 56fe13b642b2..cfa2247f6cfd 100644 --- a/helix-term/src/keymap.rs +++ b/helix-term/src/keymap.rs @@ -184,14 +184,14 @@ impl<'de> serde::de::Visitor<'de> for KeyTrieVisitor { where M: serde::de::MapAccess<'de>, { - let mut label = ""; + let mut label = String::from(""); let mut command = None; let mut mapping = HashMap::new(); let mut order = Vec::new(); - while let Some(key) = map.next_key::<&str>()? { - match key { - "label" => label = map.next_value::<&str>()?, + while let Some(key) = map.next_key::()? { + match &key as &str { + "label" => label = map.next_value::()?, "command" => command = Some(map.next_value::()?), _ => { let key_event = key.parse::().map_err(serde::de::Error::custom)?; @@ -203,7 +203,7 @@ impl<'de> serde::de::Visitor<'de> for KeyTrieVisitor { } match command { - None => Ok(KeyTrie::Node(KeyTrieNode::new(label, mapping, order))), + None => Ok(KeyTrie::Node(KeyTrieNode::new(label.as_str(), mapping, order))), Some(_command) if !order.is_empty() => { Err(serde::de::Error::custom("ambiguous mapping: 'command' is only valid with 'label', but I found other keys")) }