editor: Fix underflow panic in block map sync when blocks overlap (#51078) (cherry-pick to preview) (#51081)
zed-zippy[bot]
and
Lukas Wirth
created
Cherry-pick of #51078 to preview
----
In `BlockMap::sync`, blocks within an edited region are sorted and
processed sequentially. Each block placement computes
`rows_before_block` by subtracting `new_transforms.summary().input_rows`
from the block's target position. The `Near`/`Below` cases have a guard
that skips the block if the target is already behind the current
progress, but `Above` and `Replace` were missing this guard.
When a `Replace` block (tie_break 0) is processed before an `Above`
block (tie_break 1) at the same or overlapping position, the `Replace`
block consumes multiple input rows, advancing `input_rows` past the
`Above` block's position. The subsequent `position - input_rows`
subtraction underflows on `u32`, producing a huge `RowDelta` that wraps
`wrap_row_end` past `wrap_row_start`, creating an inverted range that
propagates through the display map layers and panics as `begin <= end
(47 <= 0)` in a rope chunk slice.
Add underflow guards to `Above` and `Replace`, matching the existing
pattern in `Near`/`Below`.
Release Notes:
- Fixed a source of underflowing subtractions causing spurious panics
Co-authored-by: Lukas Wirth <lukas@zed.dev>