Events

Paid add-on

The extension emits events you can listen to with editor.on(). All events include the transaction that triggered them.

trackedChanges:suggestionCreated

Fired when a new suggestion is created (either from user editing or restored via undo/collaboration). Programmatic commands can also include an optional reason, which is exposed on this event payload.

editor.on('trackedChanges:suggestionCreated', ({ suggestion, reason, transaction }) => {
  console.log('New suggestion:', suggestion.id, suggestion.type, reason)
})

trackedChanges:suggestionAccepted

Fired when a suggestion is accepted.

editor.on('trackedChanges:suggestionAccepted', ({ suggestionId, suggestion, transaction }) => {
  console.log('Accepted:', suggestionId)
})

trackedChanges:suggestionRejected

Fired when a suggestion is rejected.

editor.on('trackedChanges:suggestionRejected', ({ suggestionId, suggestion, transaction }) => {
  console.log('Rejected:', suggestionId)
})

trackedChanges:suggestionRemoved

Fired when a suggestion is removed from the document (e.g., by deleting an "add" suggestion's content).

editor.on(
  'trackedChanges:suggestionRemoved',
  ({ suggestionId, suggestion, removedBy, canRestore }) => {
    // removedBy is 'edit' or 'delete'
    console.log('Removed:', suggestionId, 'by', removedBy)
  },
)

trackedChanges:suggestionsUpdated

Fired after bulk operations like acceptAllSuggestions, rejectSuggestionsInRange, etc.

editor.on('trackedChanges:suggestionsUpdated', ({ suggestions, operation, affectedIds }) => {
  // operation: 'acceptAll' | 'rejectAll' | 'acceptInRange' | 'rejectInRange' | 'acceptByUser' | 'rejectByUser'
  console.log(`${operation} affected ${affectedIds.length} suggestions`)
})

trackedChanges:suggestionChanged

Fired whenever any content-bearing field of a suggestion changes — including range positions, text content, mark changes, or type. Use this event as the single source of truth for keeping external state (such as comment thread metadata) in sync with a suggestion.

The payload includes both the previous and updated suggestion so you can diff exactly what changed.

editor.on(
  'trackedChanges:suggestionChanged',
  ({ suggestionId, oldSuggestion, suggestion, transaction }) => {
    console.log('Suggestion updated:', suggestionId)
    console.log('Previous text:', oldSuggestion.text, '→ New text:', suggestion.text)
  },
)

trackedChanges:suggestionRangeChanged

Fired when a suggestion's document positions shift due to other edits in the document. This event fires only on positional changes — it does not fire when non-positional fields like text or markChanges change. For a broader change signal, prefer trackedChanges:suggestionChanged.

editor.on(
  'trackedChanges:suggestionRangeChanged',
  ({ suggestionId, oldRange, newRange, suggestion }) => {
    console.log(
      `Suggestion ${suggestionId} moved from ${oldRange.from}-${oldRange.to} to ${newRange.from}-${newRange.to}`,
    )
  },
)

trackedChanges:enabled

Fired when track changes mode is enabled.

editor.on('trackedChanges:enabled', ({ userId }) => {
  console.log('Track changes enabled for', userId)
})

trackedChanges:disabled

Fired when track changes mode is disabled.

editor.on('trackedChanges:disabled', ({ userId }) => {
  console.log('Track changes disabled')
})