summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorqkzk <qu3nt1n@gmail.com>2023-11-05 18:37:16 +0100
committerqkzk <qu3nt1n@gmail.com>2023-11-05 18:37:16 +0100
commitcd52d2a0379b51861fd9b18a90db41809b655c68 (patch)
treecde881237ec0f642fc543fb48b621383f62199b7
parent24047aeb4af565ba1eb25d6948aeec8ea83c7531 (diff)
tree select last. Ugly fix
-rw-r--r--src/tab.rs5
-rw-r--r--src/trees.rs17
2 files changed, 18 insertions, 4 deletions
diff --git a/src/tab.rs b/src/tab.rs
index e9c39e5..2abae8f 100644
--- a/src/tab.rs
+++ b/src/tab.rs
@@ -386,9 +386,8 @@ impl Tab {
/// Go to the last leaf.
pub fn tree_go_to_bottom_leaf(&mut self) -> Result<()> {
- self.directory.tree.set_required_height_to_max();
- self.directory.unselect_children();
- self.directory.go_to_bottom_leaf()
+ self.tree.select_last();
+ Ok(())
}
/// Returns the current path.
diff --git a/src/trees.rs b/src/trees.rs
index ad94120..0b77f62 100644
--- a/src/trees.rs
+++ b/src/trees.rs
@@ -70,6 +70,7 @@ impl Node {
pub struct FileSystem {
root_path: PathBuf,
selected: PathBuf,
+ last_path: PathBuf,
nodes: HashMap<PathBuf, Node>,
required_height: usize,
}
@@ -90,6 +91,7 @@ impl FileSystem {
let mut stack = vec![root_path.to_owned()];
let mut nodes: HashMap<PathBuf, Node> = HashMap::new();
+ let mut last_path = root_path.to_owned();
while let Some(path) = stack.pop() {
let reached_depth = path.components().collect::<Vec<_>>().len();
if reached_depth >= depth + start_depth {
@@ -114,6 +116,7 @@ impl FileSystem {
};
}
}
+ last_path = node.path.to_owned();
nodes.insert(node.path.to_owned(), node);
}
@@ -124,6 +127,7 @@ impl FileSystem {
Self {
selected: root_path.clone(),
root_path,
+ last_path,
nodes,
required_height: Self::REQUIRED_HEIGHT,
}
@@ -133,6 +137,7 @@ impl FileSystem {
Self {
root_path: PathBuf::default(),
selected: PathBuf::default(),
+ last_path: PathBuf::default(),
nodes: HashMap::new(),
required_height: 0,
}
@@ -266,7 +271,17 @@ impl FileSystem {
self.selected = self.root_path.to_owned();
}
- pub fn select_last(&mut self) {}
+ pub fn select_last(&mut self) {
+ let Some(selected_node) = self.nodes.get_mut(&self.selected) else {
+ unreachable!("selected path should be in node")
+ };
+ selected_node.unselect();
+ let Some(last_node) = self.nodes.get_mut(&self.last_path) else {
+ unreachable!("root path should be in nodes")
+ };
+ last_node.select();
+ self.selected = self.last_path.to_owned();
+ }
/// Fold selected node
pub fn toggle_fold(&mut self) {