Skip to content

replaceParagraphTextRange should emit w:rPrChange when run formatting changes #173

@stevenobiajulu

Description

@stevenobiajulu

Context

Discovered during peer review of #143 ([120.8] regression suite — final sub-PR for #120).

packages/docx-core/SUPPORT.md Table A row for text.ts:replaceParagraphTextRange lists element set w:ins, w:del, w:rPrChange. The current implementation (#136) emits w:ins and w:del correctly but does NOT emit w:rPrChange, even when the replacement runs differ in formatting from the original.

The Group A regression test in #143 asserts the actual current behavior (ins/del only) without checking rPrChange — locking the gap into the test suite as a known limitation.

The gap

replaceParagraphTextRange accepts a ReplacementPart[] argument that can specify addRunProps (bold, italic, color changes). When these differ from the source run's properties, the new content effectively has different formatting than the original. OOXML's tracked-change model would expect a w:rPrChange to record the prior run-property state.

Current behavior:

  • Old runs are wrapped in <w:del> (correct)
  • New runs are wrapped in <w:ins> (correct)
  • The fact that the new runs have DIFFERENT <w:rPr> than the old runs is NOT captured as a property change — it's just an insertion of new-formatted content + deletion of old-formatted content

For pure text replacements with same formatting, this is fine. For formatting-aware replacements (e.g., AI changing bold-text-X to italic-text-Y), the lack of rPrChange means the document's revision history doesn't fully capture the formatting transition.

Proposal

When ReplacementPart.addRunProps is provided AND results in <w:rPr> that differs from the source run's <w:rPr>:

  • Emit a <w:rPrChange> inside each new run's <w:rPr> recording the source run's prior properties.
  • Reuse buildRPrChangeElement from the emitter module.

Acceptance criteria

  • New tests in text.test.ts cover: (a) replacement with same formatting → no rPrChange (current behavior preserved); (b) replacement with different formatting → rPrChange emitted with source run's prior rPr.
  • The Group A regression test in canonical-emission-regression.test.ts is updated to assert rPrChange when applicable.
  • SUPPORT.md note for this row is updated to "Verified by [120.8] regression test (after #)".

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requesttracked-changesTracked changes, comments, revision markers

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions