summaryrefslogtreecommitdiffstats
path: root/src/tab.rs
diff options
context:
space:
mode:
authorqkzk <qu3nt1n@gmail.com>2023-10-11 21:50:09 +0200
committerqkzk <qu3nt1n@gmail.com>2023-10-11 21:50:42 +0200
commit727f64c6a2dc385e28fbf54d686cdbe28b5daebf (patch)
tree5708b3e61e6faff2aaf136917cc12bf0597a6ff6 /src/tab.rs
parent631605b3f3af1d3c1b86528611f72ac79b1fea35 (diff)
FIX: goto mode from tree node with normal file selected crashes the app
Diffstat (limited to 'src/tab.rs')
-rw-r--r--src/tab.rs17
1 files changed, 14 insertions, 3 deletions
diff --git a/src/tab.rs b/src/tab.rs
index ad42845..b0846ea 100644
--- a/src/tab.rs
+++ b/src/tab.rs
@@ -326,11 +326,22 @@ impl Tab {
}
/// Returns the current path.
- /// It Tree mode, it's the path of the selected node.
- /// Else, it's the current path of pathcontent.
+ /// In tree mode :
+ /// if the selected node is a directory, that's it.
+ /// else, it is the parent of the selected node.
+ /// In other modes, it's the current path of pathcontent.
pub fn current_path(&mut self) -> &path::Path {
match self.mode {
- Mode::Tree => &self.directory.tree.current_node.fileinfo.path,
+ Mode::Tree => {
+ let path = &self.directory.tree.current_node.fileinfo.path;
+ if path.is_dir() {
+ return path;
+ }
+ let Some(parent) = path.parent() else {
+ return path::Path::new("/");
+ };
+ parent
+ }
_ => &self.path_content.path,
}
}