cleanup
This commit is contained in:
parent
ec10ac992a
commit
d2e28b4608
1 changed files with 36 additions and 33 deletions
29
src/main.rs
29
src/main.rs
|
@ -167,30 +167,35 @@ impl Navigator {
|
||||||
fn enter(&mut self) {
|
fn enter(&mut self) {
|
||||||
if self.selected < self.editors.len() {
|
if self.selected < self.editors.len() {
|
||||||
self.editors[self.selected].enter();
|
self.editors[self.selected].enter();
|
||||||
} else {
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
let i = self.selected - self.editors.len();
|
let i = self.selected - self.editors.len();
|
||||||
|
// top entry is hardcoded to be ../
|
||||||
if i == 0 {
|
if i == 0 {
|
||||||
if let Some(parent) = self.path.parent() {
|
if let Some(parent) = self.path.parent() {
|
||||||
self.set_path(self.path.join(parent));
|
self.set_path(self.path.join(parent));
|
||||||
}
|
}
|
||||||
} else {
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
let path = &self.files[i];
|
let path = &self.files[i];
|
||||||
if path.is_dir() {
|
if path.is_dir() {
|
||||||
self.set_path(self.path.join(path));
|
self.set_path(self.path.join(path));
|
||||||
} else if path.is_file() {
|
return;
|
||||||
|
}
|
||||||
|
if path.is_file() {
|
||||||
let path = path.canonicalize().unwrap();
|
let path = path.canonicalize().unwrap();
|
||||||
let mut editor_index = self.editors.len();
|
let mut selected = self.editors.len();
|
||||||
for (i, editor) in self.editors.iter().enumerate() {
|
for (i, editor) in self.editors.iter().enumerate() {
|
||||||
if editor.path() == Some(&path) {
|
if editor.path() == Some(&path) {
|
||||||
editor_index = i;
|
selected = i;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if editor_index == self.editors.len() {
|
// no editor exists with this path
|
||||||
match Editor::open_file(
|
if selected == self.editors.len() {
|
||||||
self.clipboard.clone(),
|
match Editor::open_file(self.clipboard.clone(), path) {
|
||||||
path.canonicalize().unwrap(),
|
|
||||||
) {
|
|
||||||
Ok(editor) => self.editors.push(editor),
|
Ok(editor) => self.editors.push(editor),
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
self.message(format!("Could not open file: {err}"));
|
self.message(format!("Could not open file: {err}"));
|
||||||
|
@ -198,12 +203,10 @@ impl Navigator {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
self.selected = editor_index;
|
self.selected = selected;
|
||||||
self.open_selected();
|
self.open_selected();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn set_path(&mut self, new_path: PathBuf) {
|
fn set_path(&mut self, new_path: PathBuf) {
|
||||||
match env::set_current_dir(&new_path) {
|
match env::set_current_dir(&new_path) {
|
||||||
|
|
Loading…
Reference in a new issue