Skip to content

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

Merged
cole-miller merged 2 commits intozed-industries:mainfrom
timvermeulen:fix-split-diff-spacer
Apr 27, 2026
Merged

editor: Fix split diff spacer calculation for non-row-aligned patch groups#53098
cole-miller merged 2 commits intozed-industries:mainfrom
timvermeulen:fix-split-diff-spacer

Conversation

@timvermeulen
Copy link
Copy Markdown
Contributor

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:

before.mov

After:

after.mov

Self-Review Checklist:

  • I've reviewed my own diff for quality, security, and reliability
  • Unsafe blocks (if any) have justifying comments
  • The content is consistent with the UI/UX checklist
  • Tests cover the new/changed behavior
  • 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.

@cla-bot cla-bot Bot added the cla-signed The user has signed the Contributor License Agreement label Apr 3, 2026
@zed-codeowner-coordinator zed-codeowner-coordinator Bot requested review from a team, as-cii and dinocosta and removed request for a team April 3, 2026 20:47
@github-actions github-actions Bot added the community champion Issues filed by our amazing community champions! 🫶 label Apr 3, 2026
@cole-miller cole-miller self-assigned this Apr 4, 2026
@cole-miller cole-miller self-requested a review April 4, 2026 04:35
@cole-miller
Copy link
Copy Markdown
Member

Thanks @timvermeulen!

@cole-miller cole-miller added this pull request to the merge queue Apr 27, 2026
Merged via the queue into zed-industries:main with commit c079264 Apr 27, 2026
33 checks passed
@zed-zippy zed-zippy Bot added the PR state:needs review Used to label PRs that are in need of a post-merge approval label Apr 27, 2026
tomhoule pushed a commit that referenced this pull request Apr 27, 2026
…roups (#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.
@MrSubidubi
Copy link
Copy Markdown
Member

@zed-industries/approved

@zed-zippy zed-zippy Bot removed the PR state:needs review Used to label PRs that are in need of a post-merge approval label Apr 29, 2026
@timvermeulen timvermeulen deleted the fix-split-diff-spacer branch April 29, 2026 18:29
ebaah46 pushed a commit to ebaah46/zed that referenced this pull request May 6, 2026
…roups (zed-industries#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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed The user has signed the Contributor License Agreement community champion Issues filed by our amazing community champions! 🫶

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants