Skip to content

Commit

Permalink
Fix runtime config parse issues after rebase on latest master
Browse files Browse the repository at this point in the history
  • Loading branch information
MattCheely committed Oct 21, 2023
1 parent 22df280 commit a4a0189
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 19 deletions.
34 changes: 20 additions & 14 deletions helix-term/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<Config>(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()
}
);
Expand All @@ -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();

Expand Down
10 changes: 5 additions & 5 deletions helix-term/src/keymap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<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)?;
Expand All @@ -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"))
}
Expand Down

0 comments on commit a4a0189

Please sign in to comment.