From 727f64c6a2dc385e28fbf54d686cdbe28b5daebf Mon Sep 17 00:00:00 2001 From: qkzk Date: Wed, 11 Oct 2023 21:50:09 +0200 Subject: FIX: goto mode from tree node with normal file selected crashes the app --- src/tab.rs | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'src/tab.rs') 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, } } -- cgit v1.2.3