Commands
All editor commands provided by the Tracked Changes extension.
enableTrackedChanges()
Enable track changes mode. All subsequent edits will become suggestions.
editor.commands.enableTrackedChanges()disableTrackedChanges()
Disable track changes mode. Edits will be applied directly to the document.
editor.commands.disableTrackedChanges()toggleTrackedChanges()
Toggle track changes mode on or off.
editor.commands.toggleTrackedChanges()setTrackedChangesUser()
Change the current user for new suggestions.
| Argument | Type | Description |
|---|---|---|
userId | string | The new user ID |
userMetadata | Record<string, unknown> | null | Optional arbitrary metadata about the user |
editor.commands.setTrackedChangesUser({
userId: 'user-789',
userMetadata: { name: 'Alice Johnson' },
})acceptSuggestion()
Accept a suggestion, applying the proposed change. For insertions, the suggestion mark is removed and text is kept. For deletions, the marked text is removed. For replacements, the old text is removed and the new text is kept.
| Argument | Type | Description |
|---|---|---|
id | string | Optional suggestion ID. If omitted, uses the suggestion at the current selection. |
// Accept suggestion at selection
editor.commands.acceptSuggestion()
// Accept specific suggestion
editor.commands.acceptSuggestion({ id: 'suggestion-123' })rejectSuggestion()
Reject a suggestion, reverting the proposed change. For insertions, the marked text is removed. For deletions, the suggestion mark is removed and text is kept. For replacements, the new text is removed and the old text is kept.
| Argument | Type | Description |
|---|---|---|
id | string | Optional suggestion ID. If omitted, uses the suggestion at the current selection. |
// Reject suggestion at selection
editor.commands.rejectSuggestion()
// Reject specific suggestion
editor.commands.rejectSuggestion({ id: 'suggestion-123' })acceptAllSuggestions()
Accept all suggestions in the document.
editor.commands.acceptAllSuggestions()rejectAllSuggestions()
Reject all suggestions in the document.
editor.commands.rejectAllSuggestions()acceptSuggestionsInRange()
Accept all suggestions within a specific document position range.
| Argument | Type | Description |
|---|---|---|
from | number | Start position of the range |
to | number | End position of the range |
editor.commands.acceptSuggestionsInRange({ from: 0, to: 100 })rejectSuggestionsInRange()
Reject all suggestions within a specific document position range.
| Argument | Type | Description |
|---|---|---|
from | number | Start position of the range |
to | number | End position of the range |
editor.commands.rejectSuggestionsInRange({ from: 0, to: 100 })acceptSuggestionsByUser()
Accept all suggestions created by a specific user.
| Argument | Type | Description |
|---|---|---|
userId | string | The user ID whose suggestions to accept |
editor.commands.acceptSuggestionsByUser({ userId: 'user-123' })rejectSuggestionsByUser()
Reject all suggestions created by a specific user.
| Argument | Type | Description |
|---|---|---|
userId | string | The user ID whose suggestions to reject |
editor.commands.rejectSuggestionsByUser({ userId: 'user-123' })addTrackedInsertion()
Insert content as a tracked suggestion without enabling tracked changes mode for the whole editor. This is useful when you need to create suggestions programmatically and want the result to match a normal tracked typing transaction. The content argument accepts any Tiptap Content value, including text, HTML, or JSON node content such as an image node. When skipTrailingNode is true, the emitted transaction also sets skipTrailingNode: true, which is useful with the TrailingNode extension.
| Argument | Type | Description |
|---|---|---|
from | number | Document position where the tracked insertion should be added |
content | Content | The content to insert as a suggestion |
reason | string | Optional description included in the trackedChanges:suggestionCreated event payload |
skipTrailingNode | boolean | Optional flag that sets skipTrailingNode: true on the emitted tracked transaction |
editor.commands.addTrackedInsertion({
from: 7,
content: 'big ',
reason: 'Applied AI rewrite',
skipTrailingNode: true,
})editor.commands.addTrackedInsertion({
from: 7,
content: {
type: 'image',
attrs: {
src: '/example.png',
alt: 'Example image',
},
},
reason: 'Inserted approved image asset',
})addTrackedDeletion()
Convert an existing document range into a tracked deletion suggestion. This mirrors what happens when a user deletes content while tracked changes mode is enabled.
| Argument | Type | Description |
|---|---|---|
from | number | Start position of the range to mark as deleted |
to | number | End position of the range to mark as deleted |
reason | string | Optional description included in the trackedChanges:suggestionCreated event payload |
editor.commands.addTrackedDeletion({
from: 7,
to: 12,
reason: 'Removed outdated wording',
})addTrackedReplacement()
Replace an existing range with a tracked replacement suggestion. The replaced content becomes the deletion part of the suggestion, and the new content becomes the insertion part. The content argument accepts any Tiptap Content value, so you can replace text with a different node by passing JSON content. When skipTrailingNode is true, the emitted transaction also sets skipTrailingNode: true, which is useful with the TrailingNode extension.
| Argument | Type | Description |
|---|---|---|
from | number | Start position of the range to replace |
to | number | End position of the range to replace |
content | Content | Replacement content to insert as a tracked suggestion |
reason | string | Optional description included in the trackedChanges:suggestionCreated event payload |
skipTrailingNode | boolean | Optional flag that sets skipTrailingNode: true on the emitted tracked transaction |
editor.commands.addTrackedReplacement({
from: 7,
to: 12,
content: 'earth',
reason: 'Replaced with approved terminology',
skipTrailingNode: true,
})editor.commands.addTrackedReplacement({
from: 7,
to: 8,
content: {
type: 'image',
attrs: {
src: '/updated-diagram.png',
alt: 'Updated diagram',
},
},
reason: 'Replaced placeholder with final diagram',
})addTrackedMark()
Apply a mark to an existing range as a tracked markChange suggestion. Use this when you want to suggest formatting or another mark-level change programmatically without enabling tracked changes mode globally.
| Argument | Type | Description |
|---|---|---|
from | number | Start position of the range to mark |
to | number | End position of the range to mark |
markName | string | Name of the schema mark to add |
markAttrs | Record<string, unknown> | null | Optional attributes for the mark being tracked |
reason | string | Optional description included in the trackedChanges:suggestionCreated event payload |
editor.commands.addTrackedMark({
from: 7,
to: 12,
markName: 'bold',
reason: 'Emphasized the approved term',
})editor.commands.addTrackedMark({
from: 7,
to: 12,
markName: 'link',
markAttrs: {
href: 'https://tiptap.dev',
target: '_blank',
},
reason: 'Linked to the canonical reference',
})removeTrackedMark()
Remove a mark from an existing range as a tracked markChange suggestion. This mirrors what happens when a user removes formatting while tracked changes mode is enabled.
| Argument | Type | Description |
|---|---|---|
from | number | Start position of the range to unmark |
to | number | End position of the range to unmark |
markName | string | Name of the schema mark to remove |
markAttrs | Record<string, unknown> | null | Optional attributes used to identify the mark variant |
reason | string | Optional description included in the trackedChanges:suggestionCreated event payload |
editor.commands.removeTrackedMark({
from: 7,
to: 12,
markName: 'bold',
reason: 'Removed emphasis from the label',
})toggleTrackedMark()
Toggle a mark on an existing range with tracked mark suggestions. On mixed selections, marked segments become tracked removals and unmarked segments become tracked additions inside one command.
| Argument | Type | Description |
|---|---|---|
from | number | Start position of the range to toggle |
to | number | End position of the range to toggle |
markName | string | Name of the schema mark to toggle |
markAttrs | Record<string, unknown> | null | Optional attributes used to identify or create the mark variant |
reason | string | Optional description included in the trackedChanges:suggestionCreated event payload |
editor.commands.toggleTrackedMark({
from: 7,
to: 12,
markName: 'bold',
reason: 'Toggled emphasis based on editorial review',
})