diff --git a/src/editor.rs b/src/editor.rs index bdd85d2..059bb60 100644 --- a/src/editor.rs +++ b/src/editor.rs @@ -10,7 +10,6 @@ use std::{ io::{stdout, Write}, ops::Range, path::PathBuf, - vec, }; use crate::config::Config; @@ -18,6 +17,7 @@ use crate::util::{color_highlight, color_reset, read_line}; const TAB_SIZE: usize = 4; +#[derive(Debug, Default)] pub struct Editor { text: String, lines: Vec, @@ -30,7 +30,7 @@ pub struct Editor { message: Option, } -#[derive(Debug)] +#[derive(Debug, Default)] struct Cursor { line: usize, column: usize, @@ -44,28 +44,15 @@ impl Editor { let text = fs::read_to_string(&path)?; Ok(Editor { text, - lines: Vec::new(), - scroll: 0, - cursor: Cursor { line: 0, column: 0 }, - marker: None, path: Some(path), - active: false, - unsaved_changes: false, - message: None, + ..Default::default() }) } pub fn new(path: Option) -> Self { Editor { - text: String::new(), - lines: vec![0..0], - scroll: 0, - cursor: Cursor { line: 0, column: 0 }, - marker: None, path, - active: false, - unsaved_changes: true, - message: None, + ..Default::default() } } @@ -76,7 +63,7 @@ impl Editor { return format!("{}{}", decorator, name.to_string_lossy()); } } - "*untitled".into() + "*".into() } pub fn is_unsaved(&self) -> bool { diff --git a/src/main.rs b/src/main.rs index 49cb6a9..7bbcc68 100644 --- a/src/main.rs +++ b/src/main.rs @@ -8,7 +8,6 @@ use crossterm::{ }, }; use std::{ - cmp::Ordering, env, fs, io::{stdout, Write}, path::PathBuf, @@ -254,13 +253,9 @@ impl Navigator { self.files.push(file.path()); } self.files[1..].sort_unstable_by(|path, other| { - if path.is_dir() == other.is_dir() { - path.cmp(other) - } else if path.is_dir() { - Ordering::Less - } else { - Ordering::Greater - } + let by_type = path.is_file().cmp(&other.is_file()); + let by_name = path.cmp(other); + by_type.then(by_name) }); }