refactor: view: un-nest trie processing

This commit is contained in:
graelo 2020-06-01 12:01:53 +02:00
parent fb07f64c97
commit 57f032af7c

View file

@ -436,18 +436,21 @@ impl<'a> View<'a> {
typed_hint.push_str(&lower_key);
match self
let node = self
.lookup_trie
.get_node(&typed_hint.chars().collect::<Vec<char>>())
{
None => {
.get_node(&typed_hint.chars().collect::<Vec<char>>());
if node.is_none() {
// An unknown key was entered.
return Event::Exit;
}
Some(node) => {
let node = node.unwrap();
if node.is_leaf() {
// The last key of a hint was entered.
let match_index = node.value().expect("By construction, the Lookup Trie should have a value for each leaf.");
let match_index = node.value().expect(
"By construction, the Lookup Trie should have a value for each leaf.",
);
let mat = self.matches.get(*match_index).expect("By construction, the value in a leaf should correspond to an existing hint.");
let text = mat.text.to_string();
let uppercased = key != lower_key;
@ -458,8 +461,6 @@ impl<'a> View<'a> {
continue;
}
}
}
}
// Unknown keys are ignored.
_ => (),