diff --git a/CHANGELOG.md b/CHANGELOG.md index ad6ebab1..a312eee3 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 diff --git a/src/browser/browser_state.rs b/src/browser/browser_state.rs index bec88087..ad9a6a2a 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 f273e6c1..c57e3db3 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;