Skip to content

Preview the tracked-change redline a text.rewrite would produce, without applying it #4150

Description

@ohcedar

What I'd like

A way to ask the engine, before applying anything, what tracked insertions and deletions a tracked text.rewrite step would create. For example, doc.mutations.preview could return them per step when the plan is previewed in tracked mode:

// hypothetical
const preview = await doc.mutations.preview({
  atomic: true,
  changeMode: 'tracked',
  steps: [{ id: 's1', op: 'text.rewrite', /* target + replacement */ }],
});
preview.steps[0].redline;
// [{ type: 'equal', text: 'Contractor shall' },
//  { type: 'insert', text: ', at its sole expense,' },
//  { type: 'equal', text: ' maintain …' }]

A standalone helper that diffs two strings with the same rules the engine uses for tracked rewrites would also work.

Why

Apps that propose edits for review (from people or from AI) usually show the proposed change as a redline before it is applied, so the reviewer can decide whether to apply it. Today that preview has to come from the app's own diff, because mutations.preview reports targets and match counts but not the resulting tracked changes.

The app's diff and the engine's diff then disagree on where words and punctuation split, how numbers are split, and how alternating changes are grouped. A reviewer approves one redline and then sees a different one in the document. Exposing the engine's own result would make preview and outcome match by construction, with no guessing.

Versions

superdoc 2.29.0, @superdoc/docx-engine 0.28.0.

Activity

  1. added
    status: triage
    on Nov 12, 2026
  2. linear-code commented on Nov 12, 2026

    @linear-code
  3. caio-pizzol commented on Nov 12, 2026

    @caio-pizzol
    Contributor

    Thanks, this is a great use case.

    You're right: mutations.preview doesn't show the redline today, so apps have to guess with their own diff. We're tracking it as a feature.

    A string-diff helper alone wouldn't always match, because some changes depend on the document. So we're leaning toward having preview return the redline directly.

    Quick question: do you just need the inserted and deleted text per step, or also how changes get grouped?

  4. added
    status: queued
    and removed
    status: triage
    on Nov 12, 2026
  5. self-assigned this
    on Nov 12, 2026
  6. ohcedar commented on Nov 12, 2026

    @ohcedar
    Author

    Thanks, returning it from preview sounds right.

    The inserted and deleted text per step is what we need most, in document order with the unchanged text between the changes. For example equal / delete / insert / equal …, split exactly as the document will show it after apply. That lets the preview read the same as the result.

    If by grouping you mean those split points, which words land in one change versus separate ones, then yes, that part matters to us. Knowing which segments form a single tracked change (for example, a delete plus an insert as one replacement) would be nice to have, but we can do without it.

    The goal is to allow us to render a preview of the entire tracked change to the user, so they can decide whether to apply it to the document or not. The more it looks like the real final superdoc redline the better.

    Screenshot from my current app shows what we are going for, and I have it working pretty well, but every once in a while the superdoc redline will look different than the one I calculate in-app so the user doesn't quite get the exact thing they approved.

    Pasted 2026-11-12 at 9 44 41 AM
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

status: queued

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions