Support expanding operation

This commit is contained in:
Hanno Braun 2024-12-11 21:45:40 +01:00
parent ffee556a97
commit ea792690f2
2 changed files with 23 additions and 0 deletions

View File

@ -102,6 +102,9 @@ impl ApplicationHandler for App {
Key::Named(NamedKey::ArrowDown) => {
self.view.select_next();
}
Key::Named(NamedKey::ArrowRight) => {
self.view.selected_mut().select_last();
}
Key::Named(NamedKey::ArrowUp) => {
self.view.select_previous();
}

View File

@ -70,6 +70,26 @@ impl OperationView {
.unwrap_or(self)
}
pub fn selected_mut(&mut self) -> &mut Self {
let Some(selected) = self.selected else {
return self;
};
// The way this is done, first checking for `is_none` and then
// `unwrap`ing below, is really ugly. But the borrow checker is forcing
// my hand.
//
// I've tried several variations of matching, and it can't see that in
// the `None` case, `self` no longer needs to be borrowed, preventing me
// from `returning it.
if self.children.get_mut(selected).is_none() {
return self;
};
self.children.get_mut(selected).unwrap().selected_mut()
}
fn last_index(&self) -> usize {
self.children.len().saturating_sub(1)
}