summaryrefslogtreecommitdiffstats
path: root/src/tree.rs
diff options
context:
space:
mode:
authorqkzk <qu3nt1n@gmail.com>2023-11-07 01:05:43 +0100
committerqkzk <qu3nt1n@gmail.com>2023-11-07 01:05:43 +0100
commit7047cce927791ca386a87edf289d2fd1a5cbd91b (patch)
tree3c4b570073b4b01b1927aac919e6870d67b84f60 /src/tree.rs
parenta2f1aea562571defe922f0d6ce13220e0e4b9c3f (diff)
first step in regrouping tree movement into a trait
Diffstat (limited to 'src/tree.rs')
-rw-r--r--src/tree.rs27
1 files changed, 26 insertions, 1 deletions
diff --git a/src/tree.rs b/src/tree.rs
index 5d9d5fd..68229e7 100644
--- a/src/tree.rs
+++ b/src/tree.rs
@@ -86,6 +86,31 @@ impl Node {
self.children = children
}
}
+pub trait Go {
+ fn go(&mut self, direction: To);
+}
+
+pub enum To<'a> {
+ Next,
+ Prev,
+ Root,
+ Last,
+ Parent,
+ Path(&'a Path),
+}
+
+impl Go for Tree {
+ fn go(&mut self, direction: To) {
+ match direction {
+ To::Next => self.select_next().unwrap_or_else(|_| ()),
+ To::Prev => self.select_prev(),
+ To::Root => self.select_root(),
+ To::Last => self.select_last(),
+ To::Parent => self.select_parent(),
+ To::Path(path) => self.select_path(path),
+ }
+ }
+}
#[derive(Debug, Clone)]
pub struct Tree {
@@ -361,7 +386,7 @@ impl Tree {
}
}
- pub fn select_from_path(&mut self, clicked_path: &Path) {
+ pub fn select_path(&mut self, clicked_path: &Path) {
let Some(new_node) = self.nodes.get_mut(clicked_path) else {
return;
};