diff options
author | Canop <cano.petrole@gmail.com> | 2024-05-04 14:41:19 +0200 |
---|---|---|
committer | Canop <cano.petrole@gmail.com> | 2024-05-04 14:41:19 +0200 |
commit | a626209cd931b582059266065f90276deedced85 (patch) | |
tree | 80b67fa033e3b61cf5482e440d81c31880604c90 | |
parent | c7a1886ed98dbadea0b6ea483fd0254458a5bad6 (diff) | |
parent | 7feece52b1ca104e8afb7cd216346705f8d2cdc8 (diff) |
Merge remote-tracking branch 'origin/main'
-rw-r--r-- | CHANGELOG.md | 1 | ||||
-rw-r--r-- | src/browser/browser_state.rs | 29 | ||||
-rw-r--r-- | src/tree/tree.rs | 3 |
3 files changed, 24 insertions, 9 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index ad6ebab..a312eee 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ ### next - `-{flags}` verb lets you change the state the same way you do it at start, eg `:-sd` to show sizes and dates +- calling `:focus` on the tree root now goes up the tree (experimental) ### v1.37.0 - 2024-04-28 <a name="v1.37.0"></a> diff --git a/src/browser/browser_state.rs b/src/browser/browser_state.rs index bec8808..ad9a6a2 100644 --- a/src/browser/browser_state.rs +++ b/src/browser/browser_state.rs @@ -347,15 +347,26 @@ impl PanelState for BrowserState { CmdResult::PopState } } - Internal::focus => internal_focus::on_internal( - internal_exec, - input_invocation, - trigger_type, - &self.displayed_tree().selected_line().path, - self.displayed_tree().options.clone(), - app_state, - cc, - ), + Internal::focus => { + let tree = self.displayed_tree(); + let mut path = &tree.selected_line().path; + let parent; + if tree.is_root_selected() { + if let Some(parent_path) = path.parent() { + parent = parent_path.to_path_buf(); + path = &parent; + } + } + internal_focus::on_internal( + internal_exec, + input_invocation, + trigger_type, + path, + tree.options.clone(), + app_state, + cc, + ) + } Internal::select => internal_select::on_internal( internal_exec, input_invocation, diff --git a/src/tree/tree.rs b/src/tree/tree.rs index f273e6c..c57e3db 100644 --- a/src/tree/tree.rs +++ b/src/tree/tree.rs @@ -302,6 +302,9 @@ impl Tree { pub fn root(&self) -> &PathBuf { &self.lines[0].path } + pub fn is_root_selected(&self) -> bool { + self.selection == 0 + } /// select the line with the best matching score pub fn try_select_best_match(&mut self) { let mut best_score = 0; |