···1919# Run all tests
2020test:
2121 cargo nextest r {{_cargo_flags}}
2222-2222+reset:
2323+ rm -rf ZettleKasten
2424+ cargo run -- init
23252426# Only used to build / generate entities
2527dev-db := justfile_directory() + "/target/dev.db"
+31-1
src/tui/components/todo/explorer.rs
···66use tracing::debug;
77use tree::NodeId;
8899-use crate::types::{TodoNode, TodoNodeKind, TodoTree};
99+use crate::types::{Group, TodoNode, TodoNodeKind, TodoTree};
10101111pub struct Explorer<'text> {
1212 pub render_list: ratatui::widgets::List<'text>,
···7878 .border_style(Style::new().fg(Color::Gray))
7979 .border_type(BorderType::Rounded),
8080 );
8181+ }
8282+8383+ /// Returns the parent `Group` of the current selection in the `Explorer`
8484+ pub fn group_of_current_selection<'tree>(&self, tree: &'tree TodoTree) -> Option<&'tree Group> {
8585+ let selected = self.id_list.get(self.state.selected()?)?;
8686+8787+ if let TodoNodeKind::Group(group) = &tree
8888+ .tree
8989+ .get(selected)
9090+ .expect("Invaraint Broken! This must be a valid id")
9191+ .data()
9292+ .kind
9393+ {
9494+ return Some(group);
9595+ }
9696+9797+ let mut ancestors = tree.tree.ancestors(selected).expect("Must be a valid id");
9898+9999+ ancestors
100100+ .next()
101101+ .and_then(|parent| match &parent.data().kind {
102102+ TodoNodeKind::Root => None,
103103+104104+ TodoNodeKind::Task(_) => {
105105+ panic!("Invariant broken! how is a task a parent?!")
106106+ }
107107+108108+ TodoNodeKind::Group(group) => Some(group),
109109+ })
110110+ .map(|g| &**g)
81111 }
82112}
83113