Skip to content

fix(cockpit): show a changed block as its removals, then its additions - #96

Merged
dawid-walkiewicz merged 1 commit into
mainfrom
fix/diff-interleaved-add-remove-lines
Nov 13, 2026
Merged

dawid-walkiewicz merged 1 commit into
mainfrom
fix/diff-interleaved-add-remove-lines

Conversation

@dawid-walkiewicz

@dawid-walkiewicz dawid-walkiewicz commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Problem

In the cockpit's diff, a rewritten paragraph showed its removed and added lines one after another (- + - + - +), so you couldn't read the old text or the new text from start to finish. GitHub shows the whole removed block first, then the whole added block.

Fix

diff2html pairs each removed line with the added line it most resembles, which is how it marks the changed words, and then prints the pairs in turn. groupChangedRows (web/src/diffrows.ts) reorders the rendered rows: within each run of changed lines, all removals first, then all additions, each side in its original order. Context lines and @@ headers still split runs, so no change moves past unchanged text. The word marks stay because only the row order changes.

Verification

  • web/src/diffrows.test.ts: a block is grouped, the word marks survive, and nothing moves across context or a hunk header
  • pnpm typecheck && pnpm test pass

🤖 Generated with Claude Code


Autofix with [code]smith
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

diff2html's line matching pairs each removed line with the added line it
most resembles and prints the pairs in turn, so a rewritten paragraph read
as - + - + and neither version could be read through. Regroup each run of
changed rows the way GitHub lays it out — every removal, then every
addition — keeping the word marks the matching produced.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dawid-walkiewicz
dawid-walkiewicz merged commit 2aecc80 into main Nov 13, 2026
8 checks passed
@dawid-walkiewicz
dawid-walkiewicz deleted the fix/diff-interleaved-add-remove-lines branch November 13, 2026 12:23
@github-actions

Copy link
Copy Markdown

🎉 This PR is included in version 1.8.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants