diff options
-rw-r--r-- | development.md | 1 | ||||
-rw-r--r-- | src/tab.rs | 6 | ||||
-rw-r--r-- | src/tree.rs | 14 |
3 files changed, 19 insertions, 2 deletions
diff --git a/development.md b/development.md index f0af9b3..f058f32 100644 --- a/development.md +++ b/development.md @@ -613,6 +613,7 @@ New view: Tree ! Toggle with 't', fold with 'z'. Navigate normally. - [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 + - [x] FIX: move up from to go to last and vice versa - [ ] search can only find the first match - [ ] test everything - [ ] refactor @@ -349,6 +349,9 @@ impl Tab { pub fn tree_page_down(&mut self) -> Result<()> { for _ in 1..10 { self.tree.select_next()?; + if self.tree.is_on_last() { + break; + } } Ok(()) } @@ -357,6 +360,9 @@ impl Tab { pub fn tree_page_up(&mut self) -> Result<()> { for _ in 1..10 { self.tree.select_prev(); + if self.tree.is_on_root() { + break; + } } Ok(()) } diff --git a/src/tree.rs b/src/tree.rs index 2491314..253e102 100644 --- a/src/tree.rs +++ b/src/tree.rs @@ -193,9 +193,16 @@ impl Tree { self.selected == self.root_path } + pub fn is_on_last(&self) -> bool { + self.selected == self.last_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()); + if self.is_on_last() { + self.select_root(); + return Ok(()); + } if let Some(next_path) = self.find_next_path() { let Some(next_node) = self.nodes.get_mut(&next_path) else { @@ -265,7 +272,10 @@ impl Tree { // TODO! find the bottom child of parent instead of jumping back 1 level /// Select previous sibling or the parent pub fn select_prev(&mut self) { - log::info!("select_prev START {sel}", sel = self.selected.display()); + if self.is_on_root() { + self.select_last(); + return; + } if let Some(previous_path) = self.find_prev_path() { let Some(previous_node) = self.nodes.get_mut(&previous_path) else { |