Skip to content

Collapsed-field multi-run replay broken in Deleted/MovedSource inplace paths #34

@stevenobiajulu

Description

@stevenobiajulu

Summary

The inplace modifier's insertDeletedRun and insertMoveFromRun functions pack all collapsed field atoms into a single <w:r>, breaking multi-run field structure. This causes orphaned fldChar elements and leaked instrText that renders as visible text in Word.

Root Cause

Asymmetry in field handling between insert and delete paths:

  • handleInserted (inPlaceModifier.ts): Correctly calls getAtomRuns(atom) and wraps each run individually — multi-run field structure preserved.
  • handleDeletedinsertDeletedRun: Calls cloneRunWithAtomContent(sourceRun, atom) which clones only the FIRST run and packs ALL field elements into it.
  • handleMovedSourceinsertMoveFromRun: Same bug.

Observed Output (before fix)

<w:del>
  <w:r>
    <w:fldChar w:fldCharType="begin"/>
    <w:instrText> PAGEREF _Toc123 \h </w:instrText>
    <w:fldChar w:fldCharType="separate"/>
    <w:delText>23</w:delText>
    <w:fldChar w:fldCharType="end"/>
  </w:r>
</w:del>

Expected Output (after fix)

<w:del>
  <w:r><w:fldChar w:fldCharType="begin"/></w:r>
  <w:r><w:instrText> PAGEREF _Toc123 \h </w:instrText></w:r>
  <w:r><w:fldChar w:fldCharType="separate"/></w:r>
  <w:r><w:delText>23</w:delText></w:r>
  <w:r><w:fldChar w:fldCharType="end"/></w:r>
</w:del>

Fix

Added filterRun parameter to getInsertableAtomContentElements (Approach A). Both insertDeletedRun and insertMoveFromRun now call getAtomRuns() and emit one cloned run per original source run.

Tests

Regression tests in collapsed-field-inplace.test.ts:

  • Dedicated-run field (PAGEREF): 6 tests
  • Mixed-run field (REF with surrounding text): 4 tests
  • Edge cases: 1 test

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions