editor: Fix BlockMapWriter::blocks_intersecting_buffer_range creating invalid indexing ranges (#38325)
Fixes ZED-113 Release Notes: - N/A *or* Added/Fixed/Improved ...
This commit is contained in:
@@ -1264,36 +1264,30 @@ impl BlockMapWriter<'_> {
|
|||||||
range: Range<usize>,
|
range: Range<usize>,
|
||||||
inclusive: bool,
|
inclusive: bool,
|
||||||
) -> &[Arc<CustomBlock>] {
|
) -> &[Arc<CustomBlock>] {
|
||||||
|
if range.is_empty() && !inclusive {
|
||||||
|
return &[];
|
||||||
|
}
|
||||||
let wrap_snapshot = self.0.wrap_snapshot.borrow();
|
let wrap_snapshot = self.0.wrap_snapshot.borrow();
|
||||||
let buffer = wrap_snapshot.buffer_snapshot();
|
let buffer = wrap_snapshot.buffer_snapshot();
|
||||||
|
|
||||||
let start_block_ix = match self.0.custom_blocks.binary_search_by(|block| {
|
let start_block_ix = match self.0.custom_blocks.binary_search_by(|block| {
|
||||||
let block_end = block.end().to_offset(buffer);
|
let block_end = block.end().to_offset(buffer);
|
||||||
block_end.cmp(&range.start).then_with(|| {
|
block_end.cmp(&range.start).then(Ordering::Greater)
|
||||||
if inclusive || (range.is_empty() && block.start().to_offset(buffer) == block_end) {
|
}) {
|
||||||
Ordering::Greater
|
Ok(ix) | Err(ix) => ix,
|
||||||
} else {
|
};
|
||||||
Ordering::Less
|
let end_block_ix = match self.0.custom_blocks[start_block_ix..].binary_search_by(|block| {
|
||||||
}
|
let block_start = block.start().to_offset(buffer);
|
||||||
|
block_start.cmp(&range.end).then(if inclusive {
|
||||||
|
Ordering::Less
|
||||||
|
} else {
|
||||||
|
Ordering::Greater
|
||||||
})
|
})
|
||||||
}) {
|
}) {
|
||||||
Ok(ix) | Err(ix) => ix,
|
Ok(ix) | Err(ix) => ix,
|
||||||
};
|
};
|
||||||
let end_block_ix = match self.0.custom_blocks.binary_search_by(|block| {
|
|
||||||
block
|
|
||||||
.start()
|
|
||||||
.to_offset(buffer)
|
|
||||||
.cmp(&range.end)
|
|
||||||
.then(if inclusive {
|
|
||||||
Ordering::Less
|
|
||||||
} else {
|
|
||||||
Ordering::Greater
|
|
||||||
})
|
|
||||||
}) {
|
|
||||||
Ok(ix) | Err(ix) => ix,
|
|
||||||
};
|
|
||||||
|
|
||||||
&self.0.custom_blocks[start_block_ix..end_block_ix]
|
&self.0.custom_blocks[start_block_ix..][..end_block_ix]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user