Skip to content

fix(coding-agent): preserve indentation in rendered diffs - #9274

Open
dannote wants to merge 1 commit into
earendil-works:mainfrom
dannote:fix/render-diff-indentation
Open

dannote wants to merge 1 commit into
earendil-works:mainfrom
dannote:fix/render-diff-indentation

Conversation

@dannote

@dannote dannote commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

Problem

The edit tool's intra-line renderer can drop indentation from a removed line when text is inserted before otherwise unchanged content.

For example, this input:

-83   await commitRecordingChunk({
+83   const result = await commitRecordingChunk({

was rendered as:

-83 await commitRecordingChunk({
+83   const result = await commitRecordingChunk({

diffWords() groups the shared leading spaces into the added segment (" const result = "). The existing highlighting logic moved those spaces outside inverse styling, but only appended them to the added line.

Solution

Extract whitespace shared by both lines before calling diffWords(), then initialize both rendered lines with that prefix. This preserves indentation without changing the existing word-level highlighting behavior. The existing handling for whitespace that belongs to only one side remains unchanged.

Added regression coverage for:

  • insertion before indented content;
  • replacement within indented content;
  • keeping shared indentation outside inverse highlighting.

Validation

  • npm run check
  • ./test.sh
  • targeted packages/coding-agent/test/diff.test.ts (3 tests)

@gaoanze888 gaoanze888 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed exact head 9b97cd9 against current main. Extracting the shared leading whitespace before diffWords() preserves indentation on both removed and added lines without changing one-sided whitespace handling. The extraction occurs after tab normalization, and only the paired single-line intra-line branch changes; context, standalone additions/removals, ANSI-aware wrapping, and selection paths remain unchanged. The focused regression suite passes 3/3 locally and covers prefix insertion, indented replacement, and keeping shared indentation outside inverse highlighting. No blocker found.

@davidbrai

Copy link
Copy Markdown
Contributor

@gaoanze888 thank you for your interest in helping with PRs and issues but posting AI agent based reviews is not helpful for us.
please don't post these kind of messages because it adds noise to the system.

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants