diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/event_exec.rs | 2 | ||||
-rw-r--r-- | src/tab.rs | 13 | ||||
-rw-r--r-- | src/tree.rs | 8 |
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(); } @@ -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()); |