This commit is contained in:
Crispy 2023-03-15 18:59:02 +01:00
parent 29660e90c6
commit b37026bae8
2 changed files with 8 additions and 26 deletions

View file

@ -10,7 +10,6 @@ use std::{
io::{stdout, Write}, io::{stdout, Write},
ops::Range, ops::Range,
path::PathBuf, path::PathBuf,
vec,
}; };
use crate::config::Config; use crate::config::Config;
@ -18,6 +17,7 @@ use crate::util::{color_highlight, color_reset, read_line};
const TAB_SIZE: usize = 4; const TAB_SIZE: usize = 4;
#[derive(Debug, Default)]
pub struct Editor { pub struct Editor {
text: String, text: String,
lines: Vec<Line>, lines: Vec<Line>,
@ -30,7 +30,7 @@ pub struct Editor {
message: Option<String>, message: Option<String>,
} }
#[derive(Debug)] #[derive(Debug, Default)]
struct Cursor { struct Cursor {
line: usize, line: usize,
column: usize, column: usize,
@ -44,28 +44,15 @@ impl Editor {
let text = fs::read_to_string(&path)?; let text = fs::read_to_string(&path)?;
Ok(Editor { Ok(Editor {
text, text,
lines: Vec::new(),
scroll: 0,
cursor: Cursor { line: 0, column: 0 },
marker: None,
path: Some(path), path: Some(path),
active: false, ..Default::default()
unsaved_changes: false,
message: None,
}) })
} }
pub fn new(path: Option<PathBuf>) -> Self { pub fn new(path: Option<PathBuf>) -> Self {
Editor { Editor {
text: String::new(),
lines: vec![0..0],
scroll: 0,
cursor: Cursor { line: 0, column: 0 },
marker: None,
path, path,
active: false, ..Default::default()
unsaved_changes: true,
message: None,
} }
} }
@ -76,7 +63,7 @@ impl Editor {
return format!("{}{}", decorator, name.to_string_lossy()); return format!("{}{}", decorator, name.to_string_lossy());
} }
} }
"*untitled".into() "*<untitled>".into()
} }
pub fn is_unsaved(&self) -> bool { pub fn is_unsaved(&self) -> bool {

View file

@ -8,7 +8,6 @@ use crossterm::{
}, },
}; };
use std::{ use std::{
cmp::Ordering,
env, fs, env, fs,
io::{stdout, Write}, io::{stdout, Write},
path::PathBuf, path::PathBuf,
@ -254,13 +253,9 @@ impl Navigator {
self.files.push(file.path()); self.files.push(file.path());
} }
self.files[1..].sort_unstable_by(|path, other| { self.files[1..].sort_unstable_by(|path, other| {
if path.is_dir() == other.is_dir() { let by_type = path.is_file().cmp(&other.is_file());
path.cmp(other) let by_name = path.cmp(other);
} else if path.is_dir() { by_type.then(by_name)
Ordering::Less
} else {
Ordering::Greater
}
}); });
} }