Search code examples
monaco-editor

How to specify the background color for when Monaco is read-only?


I want to define the background color in Monaco for when it's readonly in my theme.

I already have my theme defined with something like this:

monaco.editor.defineTheme("myCustomTheme", {
    base: "vs", 
    inherit: true, 
    rules: [],
    colors: {
        "editor.foreground": "#ffffff",
        "editor.background": "#ffffff",
    },
});

Is there a way to specify that the background should be gray if monaco is read-only and white otherwise?

Do I need to create a separate theme for read-only and switch between the two themes (readonly and editable)?

Should I just use CSS to manually change the background color?

Is there a "rule" I can use or a property in "colors" that can be applied to monaco when it's readonly?


Solution

  • I ended up creating a separate theme for when the editor is readonly and using setTheme to switch to it.