summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCanop <cano.petrole@gmail.com>2020-11-27 19:41:30 +0100
committerCanop <cano.petrole@gmail.com>2020-11-27 19:41:30 +0100
commitf1a05da9e1f7abcf00c90c54a75eca354351c7e8 (patch)
tree79575f195bae5be1ff0b59c82efce44160c5387f
parentba9dbf6c0a3827fe6299f3de582db6fc1ce9362a (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.md3
-rw-r--r--Cargo.lock2
-rw-r--r--Cargo.toml2
-rw-r--r--src/browser/browser_state.rs8
-rw-r--r--src/tree/tree.rs26
-rw-r--r--src/verb/internal.rs2
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
diff --git a/Cargo.lock b/Cargo.lock
index e96b322..0cef8cf 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -115,7 +115,7 @@ dependencies = [
[[package]]
name = "broot"
-version = "1.0.6"
+version = "1.0.7-dev"
dependencies = [
"ansi_colours",
"bet",
diff --git a/Cargo.toml b/Cargo.toml
index 5d52c30..54aec06 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -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",