diff options
author | Canop <cano.petrole@gmail.com> | 2022-02-15 17:14:06 +0100 |
---|---|---|
committer | Canop <cano.petrole@gmail.com> | 2022-02-15 17:14:06 +0100 |
commit | af3a1f3c3290f6b88c748bde656ef99ada1f3c7b (patch) | |
tree | 4a8ce6c617602b80c8de9d10b220694ce221275d /src | |
parent | 8ca1c3d09aaab7883f8ce9394fe7c43d96308903 (diff) |
:previous_dir and :next_dir internals
Fix #502
Diffstat (limited to 'src')
-rw-r--r-- | src/browser/browser_state.rs | 24 | ||||
-rw-r--r-- | src/help/help_content.rs | 7 | ||||
-rw-r--r-- | src/tree/tree.rs | 20 | ||||
-rw-r--r-- | src/verb/builtin.rs | 6 | ||||
-rw-r--r-- | src/verb/internal.rs | 4 |
5 files changed, 44 insertions, 17 deletions
diff --git a/src/browser/browser_state.rs b/src/browser/browser_state.rs index 956e91e..94060b5 100644 --- a/src/browser/browser_state.rs +++ b/src/browser/browser_state.rs @@ -355,12 +355,32 @@ impl PanelState for BrowserState { self.displayed_tree_mut().move_selection(-count, page_height, false); CmdResult::Keep } + Internal::previous_dir => { + self.displayed_tree_mut().try_select_previous_filtered( + |line| line.is_dir(), + page_height, + ); + CmdResult::Keep + } + Internal::next_dir => { + self.displayed_tree_mut().try_select_next_filtered( + |line| line.is_dir(), + page_height, + ); + CmdResult::Keep + } Internal::previous_match => { - self.displayed_tree_mut().try_select_previous_match(page_height); + self.displayed_tree_mut().try_select_previous_filtered( + |line| line.direct_match, + page_height, + ); CmdResult::Keep } Internal::next_match => { - self.displayed_tree_mut().try_select_next_match(page_height); + self.displayed_tree_mut().try_select_next_filtered( + |line| line.direct_match, + page_height, + ); CmdResult::Keep } Internal::previous_same_depth => { diff --git a/src/help/help_content.rs b/src/help/help_content.rs index 47b93df..4ccac3a 100644 --- a/src/help/help_content.rs +++ b/src/help/help_content.rs @@ -69,13 +69,6 @@ ${features * **${feature-name}:** ${feature-description} } -## Sponsorship - -**broot** is totally free for all uses. -If you *want* to help me find time to improve it and build other free programs, consider sponsoring me. -See https://dystroy.org/broot/community/#sponsorship - - "#; /// build a markdown expander which will need to be diff --git a/src/tree/tree.rs b/src/tree/tree.rs index 822f4e5..0ff91fe 100644 --- a/src/tree/tree.rs +++ b/src/tree/tree.rs @@ -367,14 +367,20 @@ impl Tree { } false } - pub fn try_select_previous_match(&mut self, page_height: usize) -> bool { + pub fn try_select_previous_filtered<F>( + &mut self, + filter: F, + page_height: usize, + ) -> bool where + F: Fn(&TreeLine) -> bool, + { 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() { continue; } - if !line.direct_match { + if !filter(line) { continue; } if line.score > 0 { @@ -385,14 +391,20 @@ impl Tree { } false } - pub fn try_select_next_match(&mut self, page_height: usize) -> bool { + pub fn try_select_next_filtered<F>( + &mut self, + filter: F, + page_height: usize, + ) -> bool where + F: Fn(&TreeLine) -> bool, + { 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() { continue; } - if !line.direct_match { + if !filter(line) { continue; } if line.score > 0 { diff --git a/src/verb/builtin.rs b/src/verb/builtin.rs index 205b722..8bf70d6 100644 --- a/src/verb/builtin.rs +++ b/src/verb/builtin.rs @@ -121,7 +121,7 @@ pub fn builtin_verbs() -> Vec<Verb> { // but ctrl-f is useful for focusing on a file's parent // (and keep the filter) internal(focus) - .with_key(key!(l)) + .with_key(key!(L)) // hum... why this one ? .with_key(key!(ctrl-f)), internal(help) .with_key(key!(F1)) @@ -153,7 +153,7 @@ pub fn builtin_verbs() -> Vec<Verb> { StayInBroot, ) .with_auto_exec(false) - .with_key(key!(F2)), + .with_key(key!(f2)), internal_bang(start_end_panel) .with_key(key!(ctrl-p)), // the char keys for mode_input are handled differently as they're not @@ -194,7 +194,7 @@ pub fn builtin_verbs() -> Vec<Verb> { .with_key(key!(ctrl-c)) .with_key(key!(ctrl-q)) .with_shortcut("q"), - internal(refresh).with_key(key!(F5)), + internal(refresh).with_key(key!(f5)), internal(root_up) .with_key(key!(ctrl-up)), internal(root_down) diff --git a/src/verb/internal.rs b/src/verb/internal.rs index 136e718..1bc9dd8 100644 --- a/src/verb/internal.rs +++ b/src/verb/internal.rs @@ -84,6 +84,9 @@ Internals! { open_leave: "open file or directory according to OS (quit broot)" true, mode_input: "enter the input mode" false, mode_command: "enter the command mode" false, + previous_dir: "select the previous directory" false, + next_dir: "select the next directory" false, + previous_match: "select the previous match" false, next_match: "select the next match" false, next_same_depth: "select the next file at the same depth" false, no_sort: "don't sort" false, @@ -92,7 +95,6 @@ Internals! { parent: "move to the parent directory" false, panel_left: "focus panel on left" false, panel_right: "focus panel on right" false, - previous_match: "select the previous match" false, previous_same_depth: "select the previous file at the same depth" false, open_preview: "open the preview panel" true, close_preview: "close the preview panel" false, |