diff --git a/experiments/2024-12-09/src/app.rs b/experiments/2024-12-09/src/app.rs index c0a858505..774ba0f60 100644 --- a/experiments/2024-12-09/src/app.rs +++ b/experiments/2024-12-09/src/app.rs @@ -100,13 +100,13 @@ impl ApplicationHandler for App { match logical_key { Key::Named(NamedKey::ArrowDown) => { - self.view.select_next(); + self.view.parent_of_selected_mut().select_next(); } Key::Named(NamedKey::ArrowRight) => { self.view.selected_mut().select_last(); } Key::Named(NamedKey::ArrowUp) => { - self.view.select_previous(); + self.view.parent_of_selected_mut().select_previous(); } _ => {} } diff --git a/experiments/2024-12-09/src/view.rs b/experiments/2024-12-09/src/view.rs index 53b991579..b13985b9f 100644 --- a/experiments/2024-12-09/src/view.rs +++ b/experiments/2024-12-09/src/view.rs @@ -90,6 +90,28 @@ impl OperationView { self.children.get_mut(selected).unwrap().selected_mut() } + pub fn parent_of_selected_mut(&mut self) -> &mut Self { + let Some(selected) = self.selected else { + return self; + }; + + // The same comment in `selected_mut` applies here too. Plus, some ugly + // duplication. + + if self.children.get_mut(selected).is_none() { + return self; + }; + + if self.children.get_mut(selected).unwrap().selected.is_none() { + self + } else { + self.children + .get_mut(selected) + .unwrap() + .parent_of_selected_mut() + } + } + fn last_index(&self) -> usize { self.children.len().saturating_sub(1) }