Search code examples
monaco-editor

getAllDecorations is not a function


I have managed to create line and in-line decorations and apply them to the editor, this is the code I am using to create the decorations:

editor.deltaDecorations([], myDecorations);

Now I am looking for a way to remove the decorations.

I tried the getAllDecorations as described here in the API documentation https://microsoft.github.io/monaco-editor/api/interfaces/monaco.editor.itextmodelwithdecorations.html#getalldecorations, but when I try to use it like this:

var decs = editor.getAllDecorations();

I get the following error in the console of the browser:

Uncaught TypeError: editor.getAllDecorations is not a function(…)

Any suggestions as to what I am doing wrong would be greatly appreciated! TIA


Solution

  • getAllDecorations function is defined for model object, not editor, as you can see in the documentation

    https://microsoft.github.io/monaco-editor/api/interfaces/monaco.editor.imodel.html#getalldecorations

    so, you should use

    editor.getModel().getAllDecorations();