Reset buffer git diff when setting diff base to None

Co-Authored-By: Joseph Lyons <joseph@zed.dev>
This commit is contained in:
Julia 2022-10-07 12:20:54 -04:00
parent 8fb8fff61b
commit e15f27106d
2 changed files with 13 additions and 0 deletions

View file

@ -104,6 +104,11 @@ impl BufferDiff {
})
}
pub fn clear(&mut self, buffer: &text::BufferSnapshot) {
self.last_buffer_version = Some(buffer.version().clone());
self.tree = SumTree::new();
}
pub fn needs_update(&self, buffer: &text::BufferSnapshot) -> bool {
match &self.last_buffer_version {
Some(last) => buffer.version().changed_since(last),
@ -296,6 +301,9 @@ mod tests {
&diff_base,
&[(0..1, "", "point five\n"), (2..3, "two\n", "HELLO\n")],
);
diff.clear(&buffer);
assert_hunks(diff.hunks(&buffer), &buffer, &diff_base, &[]);
}
#[test]

View file

@ -707,6 +707,11 @@ impl Buffer {
}
})
.detach()
} else {
let snapshot = self.snapshot();
self.git_diff_status.diff.clear(&snapshot);
self.git_diff_update_count += 1;
cx.notify();
}
}