summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDenys Séguret <cano.petrole@gmail.com>2024-05-04 14:33:57 +0200
committerGitHub <noreply@github.com>2024-05-04 14:33:57 +0200
commit7feece52b1ca104e8afb7cd216346705f8d2cdc8 (patch)
treeb9672c7964043d75a45f02167d52a355f8e126ff
parent3c3f4e62dd9a3252f7dababe01aef3b8d5f5e4d0 (diff)
calling :focus on the tree root goes up (#875)
* calling :focus on the tree root goes up * update changelog
-rw-r--r--CHANGELOG.md3
-rw-r--r--src/browser/browser_state.rs29
-rw-r--r--src/tree/tree.rs3
3 files changed, 26 insertions, 9 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 6514fde..a2236a0 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,6 @@
+### next
+- calling `:focus` on the tree root now goes up the tree
+
### v1.37.0 - 2024-04-28
<a name="v1.37.0"></a>
- optionally display lines surrounding a matching line in preview, with `lines_before_match_in_preview` and `lines_after_match_in_preview` - Fix #756
diff --git a/src/browser/browser_state.rs b/src/browser/browser_state.rs
index bec8808..c35588a 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;