Skip to content

Commit

Permalink
Update reload to mark buffer as unmodified
Browse files Browse the repository at this point in the history
  • Loading branch information
jmacdonald committed Feb 18, 2024
1 parent 17c41bc commit cbae7a0
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/buffer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}

Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit cbae7a0

Please sign in to comment.