Fix panic when deleting just-generated text (#10282)

We ran into a panic when deleting text that was just generated by a code
action.

This fixes it by ensuring we don't run into a 0-minus-1 panic when a
buffer_range is empty.

Release Notes:

- Fixed panic that could occur when deleting generated-by-unsaved text.

Co-authored-by: Conrad <conrad@zed.dev>
This commit is contained in:
Thorsten Ball 2024-04-08 17:59:25 +02:00 committed by GitHub
parent 87c282d8f1
commit 4d68bf2fa6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -2754,10 +2754,13 @@ impl BufferSnapshot {
range.start + self.line_len(start.row as u32) as usize - start.column;
}
buffer_ranges.push((range, node_is_name));
if !range.is_empty() {
buffer_ranges.push((range, node_is_name));
}
}
if buffer_ranges.is_empty() {
matches.advance();
continue;
}