From ea792690f2e5aaa2b05b50e35a653ef343656d39 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 11 Dec 2024 21:45:40 +0100 Subject: [PATCH] Support expanding operation --- experiments/2024-12-09/src/app.rs | 3 +++ experiments/2024-12-09/src/view.rs | 20 ++++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/experiments/2024-12-09/src/app.rs b/experiments/2024-12-09/src/app.rs index c4df84666..c0a858505 100644 --- a/experiments/2024-12-09/src/app.rs +++ b/experiments/2024-12-09/src/app.rs @@ -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(); } diff --git a/experiments/2024-12-09/src/view.rs b/experiments/2024-12-09/src/view.rs index 0773a9296..53b991579 100644 --- a/experiments/2024-12-09/src/view.rs +++ b/experiments/2024-12-09/src/view.rs @@ -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) }