Compare commits
2 commits
444f12cb32
...
d2e28b4608
Author | SHA1 | Date | |
---|---|---|---|
d2e28b4608 | |||
ec10ac992a |
2 changed files with 37 additions and 41 deletions
|
@ -279,17 +279,10 @@ 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
|
||||||
.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) {
|
fn move_home(&mut self) {
|
||||||
|
|
69
src/main.rs
69
src/main.rs
|
@ -167,41 +167,44 @@ 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();
|
}
|
||||||
if i == 0 {
|
|
||||||
if let Some(parent) = self.path.parent() {
|
let i = self.selected - self.editors.len();
|
||||||
self.set_path(self.path.join(parent));
|
// top entry is hardcoded to be ../
|
||||||
}
|
if i == 0 {
|
||||||
} else {
|
if let Some(parent) = self.path.parent() {
|
||||||
let path = &self.files[i];
|
self.set_path(self.path.join(parent));
|
||||||
if path.is_dir() {
|
}
|
||||||
self.set_path(self.path.join(path));
|
return;
|
||||||
} else if path.is_file() {
|
}
|
||||||
let path = path.canonicalize().unwrap();
|
|
||||||
let mut editor_index = self.editors.len();
|
let path = &self.files[i];
|
||||||
for (i, editor) in self.editors.iter().enumerate() {
|
if path.is_dir() {
|
||||||
if editor.path() == Some(&path) {
|
self.set_path(self.path.join(path));
|
||||||
editor_index = i;
|
return;
|
||||||
break;
|
}
|
||||||
}
|
if path.is_file() {
|
||||||
}
|
let path = path.canonicalize().unwrap();
|
||||||
if editor_index == self.editors.len() {
|
let mut selected = self.editors.len();
|
||||||
match Editor::open_file(
|
for (i, editor) in self.editors.iter().enumerate() {
|
||||||
self.clipboard.clone(),
|
if editor.path() == Some(&path) {
|
||||||
path.canonicalize().unwrap(),
|
selected = i;
|
||||||
) {
|
break;
|
||||||
Ok(editor) => self.editors.push(editor),
|
|
||||||
Err(err) => {
|
|
||||||
self.message(format!("Could not open file: {err}"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
self.selected = editor_index;
|
|
||||||
self.open_selected();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// 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}"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
self.selected = selected;
|
||||||
|
self.open_selected();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue