show error when failing to navigate to directory
This commit is contained in:
parent
cf1a4c510d
commit
5035e4c295
1 changed files with 14 additions and 5 deletions
19
src/main.rs
19
src/main.rs
|
@ -171,15 +171,12 @@ impl Navigator {
|
||||||
let i = self.selected - self.editors.len();
|
let i = self.selected - self.editors.len();
|
||||||
if i == 0 {
|
if i == 0 {
|
||||||
if let Some(parent) = self.path.parent() {
|
if let Some(parent) = self.path.parent() {
|
||||||
self.path = parent.to_owned();
|
self.set_path(self.path.join(parent));
|
||||||
env::set_current_dir(&self.path).unwrap();
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let path = &self.files[i];
|
let path = &self.files[i];
|
||||||
if path.is_dir() {
|
if path.is_dir() {
|
||||||
self.path = self.path.join(path);
|
self.set_path(self.path.join(path));
|
||||||
env::set_current_dir(&self.path).unwrap();
|
|
||||||
self.selected = self.editors.len();
|
|
||||||
} else if path.is_file() {
|
} else if path.is_file() {
|
||||||
let path = path.canonicalize().unwrap();
|
let path = path.canonicalize().unwrap();
|
||||||
let mut editor_index = self.editors.len();
|
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) {
|
fn open_selected(&mut self) {
|
||||||
if self.selected < self.editors.len() {
|
if self.selected < self.editors.len() {
|
||||||
self.editors[self.selected].enter();
|
self.editors[self.selected].enter();
|
||||||
|
|
Loading…
Reference in a new issue