Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
kirawi committed Feb 19, 2023
1 parent 43cf9ba commit 92064f7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
7 changes: 3 additions & 4 deletions helix-term/src/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -515,10 +515,6 @@ impl Application {
}
};

if doc_save_event.serialize_error {
self.editor.set_error("failed to serialize history");
}

let doc = match self.editor.document_mut(doc_save_event.doc_id) {
None => {
warn!(
Expand Down Expand Up @@ -570,6 +566,9 @@ impl Application {
lines,
bytes
));
if doc_save_event.serialize_error {
self.editor.set_error("failed to serialize history");
}
}

#[inline(always)]
Expand Down
26 changes: 15 additions & 11 deletions helix-view/src/document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use std::path::{Path, PathBuf};
use std::str::FromStr;
use std::sync::Arc;
use std::time::SystemTime;
use tokio::fs::OpenOptions;

use helix_core::{
encoding,
Expand Down Expand Up @@ -591,7 +592,7 @@ impl Document {
.load()
.persistent_undo
.then(|| self.history.get_mut().clone());
let undo_file = self.undo_file(Some(&path))?.unwrap();
let undofile_path = self.undo_file(Some(&path))?.unwrap();
// We encode the file according to the `Document`'s encoding.
let future = async move {
use tokio::{fs, fs::File};
Expand Down Expand Up @@ -624,16 +625,17 @@ impl Document {
if let Some(history) = history {
let res = {
let path = path.clone();
let mut undofile = OpenOptions::new()
.write(true)
.read(true)
.create(true)
.open(&undofile_path)
.await?
.into_std()
.await;
tokio::task::spawn_blocking(move || -> anyhow::Result<()> {
use std::fs;
let append =
History::read_header(&mut fs::File::open(&undo_file)?, &path).is_ok();
let mut undo_file = std::fs::OpenOptions::new()
.write(true)
.truncate(!append)
.read(true)
.open(&undo_file)?;
history.serialize(&mut undo_file, &path, current_rev, append)?;
let append = undofile.metadata()?.len() != 0;
history.serialize(&mut undofile, &path, current_rev, append)?;
Ok(())
})
.await
Expand Down Expand Up @@ -719,6 +721,7 @@ impl Document {

// TODO: Handle error
if self.load_history().is_err() {
panic!();
// Calculate the difference between the buffer and source text, and apply it.
// This is not considered a modification of the contents of the file regardless
// of the encoding.
Expand All @@ -727,6 +730,7 @@ impl Document {
self.append_changes_to_history(view);
self.reset_modified();
}
log::info!("{:#?}", self.history.get_mut());
self.last_saved_time = SystemTime::now();

self.detect_indent_and_line_ending();
Expand Down Expand Up @@ -767,7 +771,7 @@ impl Document {
if self.history.get_mut().is_empty() {
self.history.set(history);
} else {
let offset = self.get_last_saved_revision();
let offset = self.get_last_saved_revision() + 1;
self.history.get_mut().merge(history, offset)?;
}
self.set_last_saved_revision(last_saved_revision);
Expand Down

0 comments on commit 92064f7

Please sign in to comment.