diff --git a/helix-core/.DS_Store b/helix-core/.DS_Store deleted file mode 100644 index a116e7215c8c5..0000000000000 Binary files a/helix-core/.DS_Store and /dev/null differ diff --git a/helix-core/src/history.rs b/helix-core/src/history.rs index 3e253a3c8f96b..a5867948019bb 100644 --- a/helix-core/src/history.rs +++ b/helix-core/src/history.rs @@ -2,7 +2,6 @@ use crate::parse::*; use crate::{Assoc, ChangeSet, Range, Rope, Selection, Transaction}; use once_cell::sync::Lazy; use regex::Regex; -use std::fs::File; use std::io::{Read, Write}; use std::num::NonZeroUsize; use std::time::{Duration, Instant}; @@ -68,25 +67,23 @@ struct Revision { timestamp: Instant, } -const HEADER_TAG: &str = "Helix Undofile"; -const CURRENT_VERSION: u8 = 1; +const HEADER_TAG: &str = "Helix Undofile 1\n"; pub fn serialize_history(writer: &mut W, history: &History) -> std::io::Result<()> { write_string(writer, HEADER_TAG)?; - write_byte(writer, CURRENT_VERSION)?; write_usize(writer, history.current)?; write_vec(writer, &history.revisions, serialize_revision)?; Ok(()) } pub fn deserialize_history(reader: &mut R) -> std::io::Result { - if HEADER_TAG != read_string(reader)? { + let header = read_string(reader)?; + if HEADER_TAG != header { Err(std::io::Error::new( std::io::ErrorKind::Other, - "missing undofile header", + format!("missing undofile header"), )) } else { - let _version = read_byte(reader)?; let timestamp = Instant::now(); let current = read_usize(reader)?; let revisions = read_vec(reader, |reader| deserialize_revision(reader, timestamp))?; diff --git a/helix-core/src/parse.rs b/helix-core/src/parse.rs index ce8ef6665c042..f97700c19e31b 100644 --- a/helix-core/src/parse.rs +++ b/helix-core/src/parse.rs @@ -88,9 +88,11 @@ pub fn read_usize(reader: &mut R) -> Result { pub fn read_string(reader: &mut R) -> Result { let len = read_usize(reader)?; - let mut buf = String::with_capacity(len); - reader.read_to_string(&mut buf)?; - Ok(buf) + let mut buf = vec![0; len]; + reader.read_exact(&mut buf)?; + + let res = String::from_utf8(buf).map_err(|e| Error::new(ErrorKind::InvalidData, e))?; + Ok(res) } pub fn read_vec(reader: &mut R, f: impl Fn(&mut R) -> Result) -> Result> { diff --git a/helix-core/tests/.DS_Store b/helix-core/tests/.DS_Store deleted file mode 100644 index 5008ddfcf53c0..0000000000000 Binary files a/helix-core/tests/.DS_Store and /dev/null differ diff --git a/helix-view/.DS_Store b/helix-view/.DS_Store deleted file mode 100644 index 48c29546c06bc..0000000000000 Binary files a/helix-view/.DS_Store and /dev/null differ diff --git a/helix-view/src/.DS_Store b/helix-view/src/.DS_Store deleted file mode 100644 index c7a70ec6218a6..0000000000000 Binary files a/helix-view/src/.DS_Store and /dev/null differ diff --git a/helix-view/src/editor.rs b/helix-view/src/editor.rs index 199b1376c7c1a..861a0666fbac1 100644 --- a/helix-view/src/editor.rs +++ b/helix-view/src/editor.rs @@ -830,6 +830,11 @@ impl Editor { } } + pub fn save_workspace(&self) -> anyhow::Result<()> { + let mut workspace = Workspace::new(std::env::current_dir()?)?; + Ok(()) + } + pub fn session(&self) -> anyhow::Result { Workspace::new(std::env::current_dir()?) }