diff --git a/src/buffer/mod.rs b/src/buffer/mod.rs index a69459d..9ad7a25 100644 --- a/src/buffer/mod.rs +++ b/src/buffer/mod.rs @@ -417,6 +417,10 @@ impl Buffer { self.replace(content); + // We mark the history at points where the + // buffer is in sync with its file equivalent. + self.history.mark(); + Ok(()) } @@ -554,6 +558,28 @@ mod tests { assert_eq!(*tracked_position.borrow(), Position::new()); } + #[test] + fn reload_marks_buffer_as_unmodified() { + let file_path = Path::new("tests/sample/file"); + let mut buffer = Buffer::from_file(file_path).unwrap(); + buffer.insert("amp\neditor"); + + buffer.reload().unwrap(); + + assert!(!buffer.modified()); + } + + #[test] + fn reload_retains_history() { + let file_path = Path::new("tests/sample/file"); + let mut buffer = Buffer::from_file(file_path).unwrap(); + buffer.insert("amp\neditor"); + + buffer.reload().unwrap(); + + assert!(buffer.history.previous().is_some()); + } + #[test] fn delete_joins_lines_when_invoked_at_end_of_line() { let mut buffer = Buffer::new();