Handle empty diff excerpts (#24168)
Release Notes: - Fix display, revert and undo of deleted hunks when the file is empty.
This commit is contained in:
parent
8bce896395
commit
cf4539ec79
4 changed files with 98 additions and 1318 deletions
|
@ -80,6 +80,20 @@ impl BufferDiff {
|
|||
let buffer_text = buffer.as_rope().to_string();
|
||||
let patch = Self::diff(diff_base, &buffer_text);
|
||||
|
||||
// A common case in Zed is that the empty buffer is represented as just a newline,
|
||||
// but if we just compute a naive diff you get a "preserved" line in the middle,
|
||||
// which is a bit odd.
|
||||
if buffer_text == "\n" && diff_base.ends_with("\n") && diff_base.len() > 1 {
|
||||
tree.push(
|
||||
InternalDiffHunk {
|
||||
buffer_range: buffer.anchor_before(0)..buffer.anchor_before(0),
|
||||
diff_base_byte_range: 0..diff_base.len() - 1,
|
||||
},
|
||||
buffer,
|
||||
);
|
||||
return Self { tree };
|
||||
}
|
||||
|
||||
if let Some(patch) = patch {
|
||||
let mut divergence = 0;
|
||||
for hunk_index in 0..patch.num_hunks() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue