Fix handling of empty blocks in BlockMap::chunks (#25031)

Closes https://github.com/zed-industries/zed/issues/23391

Release Notes:

- Fixed a bug that sometimes caused incorrect syntax highlighting when
deploying the inline assistant.
This commit is contained in:
Max Brunsfeld 2025-02-17 11:20:19 -08:00 committed by GitHub
parent 69477dfd8c
commit 1e1b637b50
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 31 additions and 16 deletions

View file

@ -1721,6 +1721,7 @@ impl BlockSnapshot {
impl<'a> BlockChunks<'a> {
/// Go to the next transform
fn advance(&mut self) {
self.input_chunk = Chunk::default();
self.transforms.next(&());
while let Some(transform) = self.transforms.item() {
if transform
@ -1748,7 +1749,6 @@ impl<'a> BlockChunks<'a> {
);
self.input_chunks.seek(start_input_row..end_input_row);
}
self.input_chunk = Chunk::default();
}
}
}
@ -1812,9 +1812,6 @@ impl<'a> Iterator for BlockChunks<'a> {
let (mut prefix, suffix) = self.input_chunk.text.split_at(prefix_bytes);
self.input_chunk.text = suffix;
if self.output_row == transform_end {
self.advance();
}
if self.masked {
// Not great for multibyte text because to keep cursor math correct we
@ -1824,10 +1821,16 @@ impl<'a> Iterator for BlockChunks<'a> {
prefix = &BULLETS[..bullet_len];
}
Some(Chunk {
let chunk = Chunk {
text: prefix,
..self.input_chunk.clone()
})
};
if self.output_row == transform_end {
self.advance();
}
Some(chunk)
}
}