Compare commits
No commits in common. "d2e28b4608dc28b06b2b7247d9abae084222b295" and "444f12cb323f4a169ddde86b3e260f71c957bce6" have entirely different histories.
d2e28b4608
...
444f12cb32
2 changed files with 39 additions and 35 deletions
|
@ -279,10 +279,17 @@ impl Editor {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn scroll_to_cursor(&mut self) {
|
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;
|
let height = terminal::size().unwrap().1 as usize - 2;
|
||||||
self.scroll = self
|
self.scroll = self
|
||||||
.scroll
|
.scroll
|
||||||
.clamp(self.cursor.line.saturating_sub(height), self.cursor.line);
|
.max(self.scroll + self.cursor.line.saturating_sub(self.scroll + height));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn move_home(&mut self) {
|
fn move_home(&mut self) {
|
||||||
|
|
29
src/main.rs
29
src/main.rs
|
@ -167,35 +167,30 @@ 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();
|
||||||
return;
|
} else {
|
||||||
}
|
|
||||||
|
|
||||||
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));
|
||||||
}
|
}
|
||||||
return;
|
} else {
|
||||||
}
|
|
||||||
|
|
||||||
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));
|
||||||
return;
|
} else if path.is_file() {
|
||||||
}
|
|
||||||
if path.is_file() {
|
|
||||||
let path = path.canonicalize().unwrap();
|
let path = path.canonicalize().unwrap();
|
||||||
let mut selected = self.editors.len();
|
let mut editor_index = 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) {
|
||||||
selected = i;
|
editor_index = i;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// no editor exists with this path
|
if editor_index == self.editors.len() {
|
||||||
if selected == self.editors.len() {
|
match Editor::open_file(
|
||||||
match Editor::open_file(self.clipboard.clone(), path) {
|
self.clipboard.clone(),
|
||||||
|
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}"));
|
||||||
|
@ -203,10 +198,12 @@ impl Navigator {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
self.selected = selected;
|
self.selected = editor_index;
|
||||||
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