Skip to content

[hardening] Comments and tracked changes anchor to paragraph start/end, not span offset #54

@MTCMarkFranco

Description

@MTCMarkFranco

Bug

Comments and ins/del runs are anchored to the start/end of the containing paragraph, not to the actual span offsets. The offsetInParagraph value is computed and immediately discarded:

Location: src/LambdaRag.Markup/OpenXmlMarkupService.cs line ~194

_ = offsetInParagraph; // reserved for future precise-run-split logic

CommentRangeStart is inserted before the first run; CommentRangeEnd is appended at paragraph end; InsertedRun/DeletedRun are appended at paragraph end.

Impact: Word's review pane shows the right paragraph but no highlight on the actual phrase being commented on. Reviewers cannot tell which words a comment refers to in long paragraphs. Inserts/deletes appear in the wrong position visually.

Expected: Split the run that contains offsetInParagraph (and the run that contains offsetInParagraph + span.Length) so that:

  • CommentRangeStart is placed immediately before the run starting at the span's char-start.
  • CommentRangeEnd is placed immediately after the run ending at the span's char-end.
  • InsertedRun is placed at the span's start position (for Insert/Replace).
  • DeletedRun replaces the spanned runs in place (for Delete/Replace).

Acceptance criteria

  • Run-splitting helper is implemented and unit-tested for: span entirely inside one run; span at run start; span at run end; span across two adjacent runs.
  • Comment range brackets cover only the spanned text, verified by reading back the docx and asserting bracket positions relative to text.
  • Idempotency test still passes.
  • Engine genericity guard test still passes.

Out of scope

  • Cross-paragraph spans (tracked separately).

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingmodalityOutput modality (report/markup/UI/API)phase-1-pattern-defPhase 1: Pattern definition (writing)

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions