Compare commits

..

2 commits

Author SHA1 Message Date
d2e28b4608 cleanup 2023-03-13 20:26:59 +01:00
ec10ac992a cleanup 2023-03-13 20:12:13 +01:00
2 changed files with 37 additions and 41 deletions

View file

@ -279,17 +279,10 @@ impl Editor {
}
fn scroll_to_cursor(&mut self) {
// while self.cursor.line < self.scroll {
// self.scroll -= 1;
// }
// while self.cursor.line > (self.scroll + terminal::size().unwrap().1 as usize - 2) {
// self.scroll += 1;
// }
self.scroll = self.scroll.min(self.cursor.line);
let height = terminal::size().unwrap().1 as usize - 2;
self.scroll = self
.scroll
.max(self.scroll + self.cursor.line.saturating_sub(self.scroll + height));
.clamp(self.cursor.line.saturating_sub(height), self.cursor.line);
}
fn move_home(&mut self) {

View file

@ -167,30 +167,35 @@ impl Navigator {
fn enter(&mut self) {
if self.selected < self.editors.len() {
self.editors[self.selected].enter();
} else {
return;
}
let i = self.selected - self.editors.len();
// top entry is hardcoded to be ../
if i == 0 {
if let Some(parent) = self.path.parent() {
self.set_path(self.path.join(parent));
}
} else {
return;
}
let path = &self.files[i];
if path.is_dir() {
self.set_path(self.path.join(path));
} else if path.is_file() {
return;
}
if path.is_file() {
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() {
if editor.path() == Some(&path) {
editor_index = i;
selected = i;
break;
}
}
if editor_index == self.editors.len() {
match Editor::open_file(
self.clipboard.clone(),
path.canonicalize().unwrap(),
) {
// no editor exists with this path
if selected == self.editors.len() {
match Editor::open_file(self.clipboard.clone(), path) {
Ok(editor) => self.editors.push(editor),
Err(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();
}
}
}
}
fn set_path(&mut self, new_path: PathBuf) {
match env::set_current_dir(&new_path) {