文档说它已被弃用:
(method) editor.ICodeEditor.deltaDecorations(oldDecorations: string[], newDecorations: monaco.editor.IModelDeltaDecoration[]): string[]
All decorations added through this call will get the ownerId of this editor.
@deprecated
The signature '(oldDecorations: string[], newDecorations: IModelDeltaDecoration[]): string[]' of 'editor.deltaDecorations' is deprecated.
但我发现的唯一例子仍然使用它
该文件没有说明是什么取代了它。
根据https://github.com/microsoft/monaco-editor/blob/main/CHANGELOG.md,
软弃用 ICodeEditor.deltaDecorations,无需采用。应改用 IEditor.createDecorationsCollection API。
createDecorationsCollection
返回一个 monacoT.editor.IEditorDecorationsCollection
,它有一个 .clear()
方法来删除所有先前的装饰。