Fix runtime config parse issues after rebase on latest master

Matthew Cheely 1 year ago
parent 22df28002f
commit a4a01894d9

@ -187,21 +187,27 @@ mod tests {
b = { label = "buffer", b = "buffer_picker", n = "goto_next_buffer" } 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!( assert_eq!(
toml::from_str::<Config>(sample_keymaps).unwrap(), Config::load_test(sample_keymaps),
Config { Config {
keys: hashmap! { keys,
Mode::Normal => Keymap::new(keymap!({ "Normal mode"
"f" => { ""
"f" => file_picker,
"c" => wclose,
},
"b" => { "buffer"
"b" => buffer_picker,
"n" => goto_next_buffer,
},
})),
},
..Default::default() ..Default::default()
} }
); );
@ -221,7 +227,7 @@ mod tests {
c = ":buffer-close" 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(); let tree = config.keys.get(&Mode::Normal).unwrap().root();

@ -184,14 +184,14 @@ impl<'de> serde::de::Visitor<'de> for KeyTrieVisitor {
where where
M: serde::de::MapAccess<'de>, M: serde::de::MapAccess<'de>,
{ {
let mut label = ""; let mut label = String::from("");
let mut command = None; let mut command = None;
let mut mapping = HashMap::new(); let mut mapping = HashMap::new();
let mut order = Vec::new(); let mut order = Vec::new();
while let Some(key) = map.next_key::<&str>()? { while let Some(key) = map.next_key::<String>()? {
match key { match &key as &str {
"label" => label = map.next_value::<&str>()?, "label" => label = map.next_value::<String>()?,
"command" => command = Some(map.next_value::<MappableCommand>()?), "command" => command = Some(map.next_value::<MappableCommand>()?),
_ => { _ => {
let key_event = key.parse::<KeyEvent>().map_err(serde::de::Error::custom)?; let key_event = key.parse::<KeyEvent>().map_err(serde::de::Error::custom)?;
@ -203,7 +203,7 @@ impl<'de> serde::de::Visitor<'de> for KeyTrieVisitor {
} }
match command { 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() => { Some(_command) if !order.is_empty() => {
Err(serde::de::Error::custom("ambiguous mapping: 'command' is only valid with 'label', but I found other keys")) Err(serde::de::Error::custom("ambiguous mapping: 'command' is only valid with 'label', but I found other keys"))
} }

Loading…
Cancel
Save