# editor: Fix split diff spacer calculation for non-row-aligned patch groups \(\#53098\) · gitcafe/zed

[View on GitCafe](https://git.cafe/gitcafe/zed/commit/c079264372d816193445692735e951bd03e94164)

Repository: [gitcafe/zed](https://git.cafe/gitcafe/zed)

Visibility: public

Requested revision: c079264372d816193445692735e951bd03e94164

Requested commit: c079264372d816193445692735e951bd03e94164

Commit: c079264372d816193445692735e951bd03e94164

Tree: 07ff42747d1b9235c4e39f7c51740624da2099c4

Author: Tim Vermeulen

Committer: GitHub

## Message

```
editor: Fix split diff spacer calculation for non-row-aligned patch groups (#53098)

Fixes a bug in the split diff spacer calculation when a patch group
starts mid-row, sometimes causing extra spacers to be inserted.

`spacer_blocks` already explicitly handles the case where `first_point`
isn't at the start of `edit_for_first_point.old`, but the `while let
Some(source_point) = source_points.next()` loop that follows implicitly
assumes that `source_point` is at the start of `current_range`, which in
turn seems to be based on the assumption that `current_range` starts at
the beginning of a row. As it turns out, `current_range` isn't
guaranteed to start at the beginning of a row, which can sometimes lead
to incorrect spacer blocks being inserted.

This addresses that by moving the existing `if
edit_for_first_point.old.start < first_point` logic into the loop body
as `if current_edit.old.start < current_boundary` in order to handle any
non-row-aligned patch groups, not just the first one.

Here's an example of how this bug could manifest:


https://github.com/user-attachments/assets/1d3a5b4c-e4ad-4d87-804b-c4390d25f408

After:


https://github.com/user-attachments/assets/b15acc62-33fe-4154-82e5-5cdf1806ffa7

Self-Review Checklist:

- [x] I've reviewed my own diff for quality, security, and reliability
- [x] Unsafe blocks (if any) have justifying comments
- [x] The content is consistent with the [UI/UX
checklist](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist)
- [x] Tests cover the new/changed behavior
- [x] Performance impact has been considered and is acceptable

Release Notes:

- Fixed incorrect spacer blocks sometimes appearing in the split diff
view when editing the file.
```

## Parents

- [1376130066b709f47eebcff2793f4c5ba9e761de](https://git.cafe/gitcafe/zed/commit/1376130066b709f47eebcff2793f4c5ba9e761de?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zed/tree/c079264372d816193445692735e951bd03e94164?format=markdown)
