Fix runtime config parse issues after rebase on latest master

pull/3958/head
Matthew Cheely 1 year ago
parent fa8c2372b3
commit fb649610eb

@ -187,10 +187,10 @@ mod tests {
b = { label = "buffer", b = "buffer_picker", n = "goto_next_buffer" }
"#;
assert_eq!(
toml::from_str::<Config>(sample_keymaps).unwrap(),
Config {
keys: hashmap! {
let mut keys = keymap::default();
merge_keys(
&mut keys,
hashmap! {
Mode::Normal => Keymap::new(keymap!({ "Normal mode"
"f" => { ""
"f" => file_picker,
@ -202,6 +202,12 @@ mod tests {
},
})),
},
);
assert_eq!(
Config::load_test(sample_keymaps),
Config {
keys,
..Default::default()
}
);
@ -221,7 +227,7 @@ mod tests {
c = ":buffer-close"
"#;
let config = toml::from_str::<Config>(sample_keymaps).unwrap();
let config = Config::load_test(sample_keymaps);
let tree = config.keys.get(&Mode::Normal).unwrap().root();

@ -197,14 +197,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::<String>()? {
match &key as &str {
"label" => label = map.next_value::<String>()?,
"command" => command = Some(map.next_value::<MappableCommand>()?),
_ => {
let key_event = key.parse::<KeyEvent>().map_err(serde::de::Error::custom)?;
@ -216,7 +216,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"))
}

Loading…
Cancel
Save