diff options
author | Canop <cano.petrole@gmail.com> | 2020-11-27 19:41:30 +0100 |
---|---|---|
committer | Canop <cano.petrole@gmail.com> | 2020-11-27 19:41:30 +0100 |
commit | f1a05da9e1f7abcf00c90c54a75eca354351c7e8 (patch) | |
tree | 79575f195bae5be1ff0b59c82efce44160c5387f | |
parent | ba9dbf6c0a3827fe6299f3de582db6fc1ce9362a (diff) |
:previous_same_depth and :next_same_depth internals
This can be tested with
```
[[verbs]]
invocation = "psd"
key = "ctrl-up"
internal = ":previous_same_depth"
[[verbs]]
invocation = "nsd"
key = "ctrl-down"
internal = ":next_same_depth"
```
I'm not sure it's really useful but it's costless and allows
experimentations.
Fix #308
-rw-r--r-- | CHANGELOG.md | 3 | ||||
-rw-r--r-- | Cargo.lock | 2 | ||||
-rw-r--r-- | Cargo.toml | 2 | ||||
-rw-r--r-- | src/browser/browser_state.rs | 8 | ||||
-rw-r--r-- | src/tree/tree.rs | 26 | ||||
-rw-r--r-- | src/verb/internal.rs | 2 |
6 files changed, 41 insertions, 2 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 8005ef0..9d5bfc2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +### next +* :previous_same_depth and :next_same_depth internals + <a name="v1.0.6"></a> ### v1.0.6 - 2020-11-19 * optional icons, thanks to @asdf8dfafjk (@fiAtcBr on Miaou) - See https://dystroy.org/broot/icons @@ -115,7 +115,7 @@ dependencies = [ [[package]] name = "broot" -version = "1.0.6" +version = "1.0.7-dev" dependencies = [ "ansi_colours", "bet", @@ -1,6 +1,6 @@ [package] name = "broot" -version = "1.0.6" +version = "1.0.7-dev" authors = ["dystroy <denys.seguret@gmail.com>"] repository = "https://github.com/Canop/broot" documentation = "https://dystroy.org/broot" diff --git a/src/browser/browser_state.rs b/src/browser/browser_state.rs index 8e9d3f8..f1a9b60 100644 --- a/src/browser/browser_state.rs +++ b/src/browser/browser_state.rs @@ -302,6 +302,14 @@ impl AppState for BrowserState { self.displayed_tree_mut().try_select_next_match(); AppStateCmdResult::Keep } + Internal::previous_same_depth => { + self.displayed_tree_mut().try_select_previous_same_depth(); + AppStateCmdResult::Keep + } + Internal::next_same_depth => { + self.displayed_tree_mut().try_select_next_same_depth(); + AppStateCmdResult::Keep + } Internal::page_down => { let tree = self.displayed_tree_mut(); if page_height < tree.lines.len() as i32 { diff --git a/src/tree/tree.rs b/src/tree/tree.rs index 8ac8a79..cda58c5 100644 --- a/src/tree/tree.rs +++ b/src/tree/tree.rs @@ -294,6 +294,32 @@ impl Tree { } false } + pub fn try_select_previous_same_depth(&mut self) -> bool { + let depth = self.lines[self.selection].depth; + for di in (0..self.lines.len()).rev() { + let idx = (self.selection + di) % self.lines.len(); + let line = &self.lines[idx]; + if !line.is_selectable() || line.depth != depth { + continue; + } + self.selection = idx; + return true; + } + false + } + pub fn try_select_next_same_depth(&mut self) -> bool { + let depth = self.lines[self.selection].depth; + for di in 0..self.lines.len() { + let idx = (self.selection + di + 1) % self.lines.len(); + let line = &self.lines[idx]; + if !line.is_selectable() || line.depth != depth { + continue; + } + self.selection = idx; + return true; + } + false + } pub fn try_select_previous_match(&mut self) -> bool { for di in (0..self.lines.len()).rev() { let idx = (self.selection + di) % self.lines.len(); diff --git a/src/verb/internal.rs b/src/verb/internal.rs index ca2f48c..3c80763 100644 --- a/src/verb/internal.rs +++ b/src/verb/internal.rs @@ -69,6 +69,7 @@ Internals! { open_stay_filter: "display the directory, keeping the current pattern", open_leave: "open file or directory according to OS (quit broot)", next_match: "select the next match", + next_same_depth: "select the next file at the same depth", no_sort: "don't sort", page_down: "scroll one page down", page_up: "scroll one page up", @@ -76,6 +77,7 @@ Internals! { panel_left: "focus panel on left", panel_right: "focus panel on right", previous_match: "select the previous match", + previous_same_depth: "select the previous file at the same depth", open_preview: "open the preview panel", close_preview: "close the preview panel", toggle_preview: "open/close the preview panel", |