事件
Paid add-on
该扩展会触发事件,你可以通过 editor.on() 来监听。所有事件都包含触发它们的事务。
trackedChanges:suggestionCreated
当创建新建议时触发(无论是用户编辑还是通过撤销/协作恢复)。编程命令也可以包含一个可选的 reason,该原因会暴露在该事件的负载中。
editor.on('trackedChanges:suggestionCreated', ({ suggestion, reason, transaction }) => {
console.log('新建议:', suggestion.id, suggestion.type, reason)
})trackedChanges:suggestionAccepted
当建议被接受时触发。
editor.on('trackedChanges:suggestionAccepted', ({ suggestionId, suggestion, transaction }) => {
console.log('已接受:', suggestionId)
})trackedChanges:suggestionRejected
当建议被拒绝时触发。
editor.on('trackedChanges:suggestionRejected', ({ suggestionId, suggestion, transaction }) => {
console.log('已拒绝:', suggestionId)
})trackedChanges:suggestionRemoved
当建议从文档中被删除时触发(例如,通过删除“添加”建议的内容)。
editor.on(
'trackedChanges:suggestionRemoved',
({ suggestionId, suggestion, removedBy, canRestore }) => {
// removedBy 是 'edit' 或 'delete'
console.log('已移除:', suggestionId, '通过', removedBy)
},
)trackedChanges:suggestionsUpdated
在批量操作后触发,如 acceptAllSuggestions,rejectSuggestionsInRange 等。
editor.on('trackedChanges:suggestionsUpdated', ({ suggestions, operation, affectedIds }) => {
// operation: 'acceptAll' | 'rejectAll' | 'acceptInRange' | 'rejectInRange' | 'acceptByUser' | 'rejectByUser'
console.log(`${operation} 影响了 ${affectedIds.length} 个建议`)
})trackedChanges:suggestionChanged
当建议的任何包含内容的字段发生变化时触发——包括范围位置、文本内容、标记更改或类型。请将此事件作为保持外部状态(例如评论线程元数据)与建议同步的唯一事实来源。
负载中同时包含变更前后的建议,因此你可以精确地比较发生了什么变化。
editor.on(
'trackedChanges:suggestionChanged',
({ suggestionId, oldSuggestion, suggestion, transaction }) => {
console.log('建议已更新:', suggestionId)
console.log('之前的文本:', oldSuggestion.text, '→ 新文本:', suggestion.text)
},
)trackedChanges:suggestionRangeChanged
当由于文档中的其他编辑导致建议的文档位置发生移动时触发。此事件仅在位置变化时触发——当 text 或 markChanges 等非位置字段发生变化时不会触发。对于更广泛的变更信号,请优先使用 trackedChanges:suggestionChanged。
editor.on(
'trackedChanges:suggestionRangeChanged',
({ suggestionId, oldRange, newRange, suggestion }) => {
console.log(
`建议 ${suggestionId} 从 ${oldRange.from}-${oldRange.to} 移动到 ${newRange.from}-${newRange.to}`,
)
},
)trackedChanges:enabled
启用追踪更改模式时触发。
editor.on('trackedChanges:enabled', ({ userId }) => {
console.log('启用追踪更改,用户:', userId)
})trackedChanges:disabled
禁用追踪更改模式时触发。
editor.on('trackedChanges:disabled', ({ userId }) => {
console.log('已禁用追踪更改')
})