# Tracked changes

> Record, review, attribute, and round-trip tracked suggestions.

## Modes

In `"suggesting"` mode, typing, toolbar commands, and agent tool calls record tracked suggestions instead of direct edits:

```ts
editor.view.setDocumentMode("suggesting");
```

Configure the initial mode editor-wide (`defaultDocumentMode`) or per document (`documentMode`):

```tsx
<ReviseEditor
  defaultDocumentMode="suggesting"
  initialDocuments={[{ id: "a", source: file, documentMode: "editing" }]}
/>
```

`defaultDocumentMode` applies only on open; use `view.setDocumentMode()` to change an open document. To prevent a user from switching to `"editing"` or accepting/rejecting changes, set [`role="suggester"`](https://revise.io/developer/docs/editor-sdk/guides/roles).

Configure markup rendering and conflict behavior via `settings.trackedChanges` (`markupStyle: "revise" | "word"`, `showRemovalsInReview`, `strictMode`).

## Reviewing

`editor.review` is the host-only controller for navigating, previewing, and settling tracked changes:

```ts
const state = editor.review.getState();
// { open, targetCount, openSuggestionIds, currentSuggestionIds, ... }

editor.review.open();
editor.review.next();
editor.review.acceptCurrent();
editor.review.rejectCurrent();
editor.review.acceptAll();

useEffect(() => editor.review.subscribe(setReviewState), [editor]);
```

### Targeted operations

```ts
const ids = editor.review.getOpenSuggestionIds();

editor.review.navigateToSuggestion(ids[0]);
editor.review.previewSuggestions(ids, "accept"); // preview only; pass null to clear
editor.review.acceptSuggestions(ids); // { resolved, missing, unresolved, refused? }
```

`previewCurrent()` and `previewAll()` behave identically for the current stop or whole document.

### Reviewing tool edits

Each mutation tool call returns its created IDs in `suggestionIds`. Independent text edits in plain paragraphs and list items preserve earlier pending IDs.

For overlapping edits, direct edits to pending text, formatting changes, structural rewrites, paragraphs with embedded objects, or tables with pending row/column/merge edits, re-read the change list before settling; earlier IDs are not guaranteed to stay stable.

Multi-block proposals settle atomically. If any part cannot be placed, nothing changes and the ID appears in `unresolved` and `refused` (`code: "decision_unsupported_structure"`).

### Display

```ts
editor.review.setShowRemovals(false);
editor.review.setSuggestionViewMode("final"); // "all-markup" | "final" | "original"
```

`"final"` previews all suggestions accepted; `"original"` previews all rejected. Neither mutates the document.

## Direct mode

To bypass tracked changes on a specific agent call, pass `{ directMode: true }`:

```ts
await editor.tools.execute(
  "style_blocks",
  { selectors: "*", attrs: [{ name: "fontFamily", value: "Georgia" }] },
  { directMode: true },
);
```

In `agent.run()`, `directMode` applies to every tool call in the run.

## Attribution

Human edits use `currentUser` (default `"Anonymous"`). Agent tool edits and delegated runs default to `"Revise Agent"`; override via `agent.name`:

```tsx
<ReviseEditor agent={{ name: "Acme Assistant" }} />
```

`review.getState().visibleAgentSuggestionIds` and `review.nextAgentSuggestion()` isolate agent suggestions from human edits.

<Note>
  Author names are stamped at edit time, not export time. Set `currentUser` and
  `agent.name` before edits occur.
</Note>

## Export and Word round trip

`exportDocx()` writes tracked changes as native Word OOXML revision marks. Supported round-trip markup:

| Word markup | Round-trip behavior |
| --- | --- |
| `w:ins` / `w:del` (including nested insert-in-delete) | Preserved as layered suggestions |
| `w:rPrChange`, `w:pPrChange` | Preserved with prior properties |
| Paragraph-mark (pilcrow) revisions | Preserved as pending splits/merges |
| Section-break deletions | Preserved |
| Table rows/cells/properties (`w:trPr`, `w:cellIns`, `w:cellDel`, `w:cellMerge`, `w:tblPrChange`) | Preserved as one resolvable change per table |
| Linked moves (`w:moveFrom` / `w:moveTo`) | Preserved as one atomic move suggestion; orphaned/mismatched halves import as plain delete/insert |
| Author, date, Word revision IDs, comments, and anchors inside tracked runs | Preserved |

### Proposals in Word files

First DOCX export assigns Word-derived `docxrev-N` IDs and stores Revise grouping metadata so multi-revision proposals reopen as single decisions (other editors may strip this metadata on save; Word's own revisions are not grouped across paragraphs). Grouping is per story (body, footnote, header, footer). A wholly inserted or deleted paragraph is one proposal when all runs share its paragraph mark's revision.

Limits:
- Another author's formatting change inside a wholly inserted or deleted paragraph imports as plain formatting.
- Paragraph-mark revisions in headers and footers are not imported (text revisions are).
- A paragraph mark both inserted and deleted imports as an insertion.

## Custom review panel

`listChanges()` computes pending changes in one pass on demand (call it when `review.subscribe()` indicates count changes):

```ts
for (const change of editor.review.listChanges()) {
  // { id, kind, author, authorType, createdAt, blockIds,
  //   insertedText, deletedText, description, agentModel,
  //   moveSourceBlockIds, moveDestinationBlockIds }
}

editor.review.getChange(id); // null once resolved
```

| Field | Value |
| --- | --- |
| `kind` | `"insert"`, `"delete"`, `"format"`, or `"move"` |
| `author` | User name, `"Revise Agent"`, custom `agent.name`, `"Anonymous"`, or imported Word reviewer |
| `blockIds` | Affected blocks (`navigateToSuggestion()` scrolls to these) |
| `moveSourceBlockIds`, `moveDestinationBlockIds` | Source and destination blocks for `"move"` (`deletedText` and `insertedText` hold each end) |

A single-operation replacement sets both `deletedText` and `insertedText` (typically with `kind: "delete"`). Accepting or rejecting the ID settles both halves atomically, as with moves:

```tsx
const verb =
  change.kind === "move"
    ? "moved"
    : change.kind === "format"
      ? "reformatted"
      : change.deletedText && change.insertedText
        ? "replaced"
        : change.kind === "delete"
          ? "removed"
          : "added";

<li onClick={() => editor.review.navigateToSuggestion(change.id)}>
  <b>{change.author}</b> {verb}{" "}
  <q>{change.deletedText ?? change.insertedText}</q>
  <button onClick={() => editor.review.acceptSuggestions([change.id])}>
    Accept
  </button>
</li>
```
