Disabling indent guides in Monaco Editor

Viewed 408

I've done an app with the Monaco Editor library which allows to change the language of the editor (as here). I would like to have the indentation guides except when the language is plaintext. Is it possible? I can hide the indent guide lines in the theme, but I don't know how to conditionally hide them. I didn't find any option for doing so.

1 Answers

You can set this through the renderIndentGuides property. See: https://microsoft.github.io/monaco-editor/api/interfaces/monaco.editor.ieditoroptions.html#renderindentguides

A simple monaco playground example to demonstrate this is shown below. Note that you can set this property after the editor has been created, using updateOptions.

var editor = monaco.editor.create(document.getElementById("container"), {
    value: [
        "function hello() {",
        "\tfor (let i = 0; i < 2; i++) {",
        "\t\tconsole.log('Hello world!');",
        "\t}",
        "}",
    ].join("\n"),

    language: "javascript",
    renderIndentGuides: false
});
setTimeout(function() {
    editor.updateOptions({
        renderIndentGuides: true
    });
}, 3000);

Related