Always apply up/down key to lowest-level selection

This commit is contained in:
Hanno Braun 2024-12-12 23:16:47 +01:00
parent ea792690f2
commit a260993342
2 changed files with 24 additions and 2 deletions

View File

@ -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();
}
_ => {}
}

View File

@ -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)
}