From 5035e4c295cd4366b6a8691bfbce024fc5389a29 Mon Sep 17 00:00:00 2001 From: CrispyPin Date: Sun, 12 Mar 2023 21:52:20 +0100 Subject: [PATCH] show error when failing to navigate to directory --- src/main.rs | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/main.rs b/src/main.rs index 34df99a..c707b6e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -171,15 +171,12 @@ impl Navigator { let i = self.selected - self.editors.len(); if i == 0 { if let Some(parent) = self.path.parent() { - self.path = parent.to_owned(); - env::set_current_dir(&self.path).unwrap(); + self.set_path(self.path.join(parent)); } } else { let path = &self.files[i]; if path.is_dir() { - self.path = self.path.join(path); - env::set_current_dir(&self.path).unwrap(); - self.selected = self.editors.len(); + self.set_path(self.path.join(path)); } else if path.is_file() { let path = path.canonicalize().unwrap(); let mut editor_index = self.editors.len(); @@ -208,6 +205,18 @@ impl Navigator { } } + fn set_path(&mut self, new_path: PathBuf) { + match env::set_current_dir(&new_path) { + Ok(()) => { + self.path = new_path; + self.selected = self.editors.len(); + } + Err(err) => { + self.message(format!("Could not navigate to directory: {err}")); + } + } + } + fn open_selected(&mut self) { if self.selected < self.editors.len() { self.editors[self.selected].enter();