summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorqkzk <qu3nt1n@gmail.com>2023-11-06 14:44:45 +0100
committerqkzk <qu3nt1n@gmail.com>2023-11-06 14:44:45 +0100
commit96eb525c48968251eb56bf5d311d00a19c26b96b (patch)
tree17fba59e7961314ddb59ce8273567089c8c01f84 /src
parent357b3c1bf637d5f4594b56f9997fe8475a12cca5 (diff)
FIX: move back from root should redo the parent tree
Diffstat (limited to 'src')
-rw-r--r--src/event_exec.rs2
-rw-r--r--src/tab.rs13
-rw-r--r--src/tree.rs8
3 files changed, 20 insertions, 3 deletions
diff --git a/src/event_exec.rs b/src/event_exec.rs
index ffd63fd..1238c8d 100644
--- a/src/event_exec.rs
+++ b/src/event_exec.rs
@@ -535,7 +535,7 @@ impl EventAction {
let tab = status.selected();
match tab.mode {
Mode::Normal => tab.move_to_parent()?,
- Mode::Tree => tab.tree_select_parent(),
+ Mode::Tree => tab.tree_select_parent()?,
Mode::InputSimple(_) | Mode::InputCompleted(_) => {
tab.input.cursor_left();
}
diff --git a/src/tab.rs b/src/tab.rs
index 400cd85..db5c08c 100644
--- a/src/tab.rs
+++ b/src/tab.rs
@@ -332,8 +332,17 @@ impl Tab {
/// Select the parent of current node.
/// If we were at the root node, move to the parent and make a new tree.
- pub fn tree_select_parent(&mut self) {
- self.tree.select_parent()
+ pub fn tree_select_parent(&mut self) -> Result<()> {
+ if self.tree.is_on_root() {
+ let Some(parent) = self.tree.root_path().parent() else {
+ return Ok(());
+ };
+ self.set_pathcontent(&parent.to_owned())?;
+ self.make_tree(Some(self.path_content.sort_kind.clone()))
+ } else {
+ self.tree.select_parent();
+ Ok(())
+ }
}
/// Move down 10 times in the tree
diff --git a/src/tree.rs b/src/tree.rs
index 08de5e7..2491314 100644
--- a/src/tree.rs
+++ b/src/tree.rs
@@ -165,6 +165,10 @@ impl Tree {
}
}
+ pub fn root_path(&self) -> &Path {
+ self.root_path.as_path()
+ }
+
pub fn selected_path(&self) -> &Path {
self.selected.as_path()
}
@@ -185,6 +189,10 @@ impl Tree {
Ok(self.selected.strip_prefix(&self.root_path)?)
}
+ pub fn is_on_root(&self) -> bool {
+ self.selected == self.root_path
+ }
+
/// Select next sibling or the next sibling of the parent
pub fn select_next(&mut self) -> Result<()> {
log::info!("select_next START {sel}", sel = self.selected.display());