diff options
author | qkzk <qu3nt1n@gmail.com> | 2023-11-06 14:44:45 +0100 |
---|---|---|
committer | qkzk <qu3nt1n@gmail.com> | 2023-11-06 14:44:45 +0100 |
commit | 96eb525c48968251eb56bf5d311d00a19c26b96b (patch) | |
tree | 17fba59e7961314ddb59ce8273567089c8c01f84 | |
parent | 357b3c1bf637d5f4594b56f9997fe8475a12cca5 (diff) |
FIX: move back from root should redo the parent tree
-rw-r--r-- | development.md | 1 | ||||
-rw-r--r-- | src/event_exec.rs | 2 | ||||
-rw-r--r-- | src/tab.rs | 13 | ||||
-rw-r--r-- | src/tree.rs | 8 |
4 files changed, 21 insertions, 3 deletions
diff --git a/development.md b/development.md index e531cfc..f0af9b3 100644 --- a/development.md +++ b/development.md @@ -612,6 +612,7 @@ New view: Tree ! Toggle with 't', fold with 'z'. Navigate normally. - [x] FIX: scrolling starts 1 row to low - [x] FIX: filename in first line - [x] FIX: can't "open" a folder to redo the tree there + - [x] FIX: move back from root should redo the parent tree - [ ] search can only find the first match - [ ] test everything - [ ] refactor 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()); |