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.
| 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 |
editor.commands.addTrackedInsertion({
from: 7,
content: 'big ',
reason: 'Applied AI rewrite',
})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.
| 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 |
editor.commands.addTrackedReplacement({
from: 7,
to: 12,
content: 'earth',
reason: 'Replaced with approved terminology',
})editor.commands.addTrackedReplacement({
from: 7,
to: 8,
content: {
type: 'image',
attrs: {
src: '/updated-diagram.png',
alt: 'Updated diagram',
},
},
reason: 'Replaced placeholder with final diagram',
})