monaco-editor
monaco-editor copied to clipboard
Changing theme in one editor should change all editors
monaco-editor: 0.8.0 Browser: Chrome OS: Centos 7
When I have two editors in two different html DOM elements, if I dynamically change theme on one editor using updateOptions()
function, theme properly changes on the editor, but the other editor takes some changes, for example font colors change but background does not.
The other editor should stay unchanged.
It is currently not possible to have two editors have different themes.
The problem is that I can't dynamically change theme at all, because if I change to one editor, the other one gets messed up.
Is it not possible to change it on both editors?
e.g. var editor1 = monaco.editor.create(...); var editor2 = monaco.editor.create(...); ... editor1.updateOptions({ theme: ... }); editor2.updateOptions({ theme: ... });
It is possible and that's the only way to do it in the current state, but that could add some unnecessary code. What I wanted to say is that changing theme on one editor should either affect all the editors in the same way as the editor we changed theme on, or not affect them at all. This way, it just makes some changes to other editors which makes the text in them unreadable. So I think this is more of a bug than a feature-request.
Why is not possible to have multiple editors of different themes?
-1 to Changing theme in one editor should change all editors
This is counter intuitive as the create editor function leads one to believe that themes should work on a per editor basis. There are many use cases (I have one right now which is broken) that require having multiple editors on a page styled differently. This also worked fine a few versions ago so not sure why it was changed... I'm interested in why the monaco-token-styles is injected globally as I would be open to working on a PR to fix this if necessary.
@alexandrudima is this problem solved? I have the same problem in "monaco-editor": "^0.10.1",
.
Any updates on the issue?
It is very sad that such cool editor does not support multiple themes in different editors..
Are there any plan to work on this ticket?
Looking for a good news!
No, there are no plans to support this. The root cause is that tokens are stored with resolved colors in the text buffer and the same text buffer can be shown in two distinct editors.
Oh just noticed this update here, so it means that this is an architectural design... I guess it is because you ported from VS Code which is an app base editor(Like you change the theme in one it affects all the windows). I'm sad that I'll have to move back to Ace Editor. I will be watching the repo until this feature comes.
Thanks for the updates!
Could colors of tokens be represented as CSS classes, so applying different colors can be achieved by applying different CSS rules?
Any update on this? I implemented the theme of my custom language (along hovers, completions, formatter, and an ugly surprise realizing it won't work in the same DOM as a TypeScript editor.
The solution was consuming the other theme's colors using their names. Perhaps if it's not feasible to support different color mappings, a solution could be formalizing some names for different kind of tokens. monaco API already has this categorized, I think is just a matter of enforcing theme authors to use those names so at least, in this case, there's a minimal theme consumer contract.
My two cents.
Badly needing it.... :D
Here {{name}}
has a custom theme with orange
token.... But on having a JSON response in right side Editor the color formating of left side single line editor is being override with right-side one's.
Originally It looks like...
No, there are no plans to support this. The root cause is that tokens are stored with resolved colors in the text buffer and the same text buffer can be shown in two distinct editors.
But is this also a problem when every editor uses its own model exclusively?
Btw. I really admire your work on monaco - I think monaco really stepped up the game for editors and brought the future a little bit closer! I just wished sometimes it would use more modern design techniques (like non-global / non-shared state).
sad :(
I see #1446, all editors on a page must share the same theme.
But I found different theme on one page in monaco editor playground
Does it support now? How should I do this in my project?
Thank you
The second editor is in an <iframe>
.
@alexdima I have two editor in the same page. when I set readonly option to left editor, right also is readonly, but I want to right is writeable. How I can insert my React components into iframe to have different monaco instances which doesn't affect each other?
How I can insert my React components into iframe to have different monaco instances which doesn't affect each other?
This will be difficult as iframes are a very strict separation layer. Basically, you need to split your app into two apps that communicate with each other through window.postMessage. The main app is loaded in the browser window, the second app in the iframe.
@hediet In general, I only have one React app for my website. It's so trick, difficult to write another app and put it into iframe
I can't believe there are no practical, certified solution to solve it. :(
For anyone that has bumped into this, here's what I'm doing to "fix" this: simply use css to revert the colors like so
.monaco-editor-container { /* the up most container of the editor */
filter: invert(1) hue-rotate(170deg) brightness(.8) grayscale(.3);
}
How it looks like:

from here: https://proto.school/blog/01 (click on "View Solution").
You can tweak the "theme" by changing the filter values. For example, if you want a "reader" theme (less blue), use:
.monaco-editor-container {
filter: saturate(20) sepia(0.8);
}

It's not perfect but it works for my use case.
I hope this will be taken into consideration by the team since it is really useful to have a visual distinction between two editors to signal users that they are somewhat different, not connected, or simply have distinct purposes. It's not just a matter of simply changing between dark and light themes, and so, I believe it makes a lot of sense to be able to customize each editor with different themes if we need to.
For anyone that has bumped into this, here's what I'm doing to "fix" this: simply use css to revert the colors like so
.monaco-editor-container { /* the up most container of the editor */ filter: invert(1) hue-rotate(170deg) brightness(.8) grayscale(.3); }
How it looks like:
![]()
from here: https://proto.school/blog/01 (click on "View Solution").
You can tweak the "theme" by changing the filter values. For example, if you want a "reader" theme (less blue), use:
.monaco-editor-container { filter: saturate(20) sepia(0.8); }
![]()
It's not perfect but it works for my use case.
I hope this will be taken into consideration by the team since it is really useful to have a visual distinction between two editors to signal users that they are somewhat different, not connected, or simply have distinct purposes. It's not just a matter of simply changing between dark and light themes, and so, I believe it makes a lot of sense to be able to customize each editor with different themes if we need to.
It is a nice fix. Thanks for suggesting your solution here.
Just wanted to bump this. Not sure what the exact goals are for the Monaco project, but it does seem that creating an open source shareable component that can be used outside of the VSCode context is one of them. Not being able to style multiple editors on the page differently is a big blocker to adoption by many. It's understood that this may not be a priority at all for the VS Code use case but it would be reassuring to see the maintainers acknowledging and putting some cycles into other use cases for this component. In any case, thanks for putting this out there at all - it's a nice piece of work.
unexpected, it's a very strange behavior for a standalone editor library.
Well there is a way to get your editors to have different themes as seen in: https://microsoft.github.io/monaco-editor/playground.html#customizing-the-appearence-exposed-colors
It just includes an iframe -.-
still have this problem, i just wanna use a editor to be a terminal log box, and set a theme different from main editor
Hi, is there an update on this?
Well there is a way to get your editors to have different themes as seen in: https://microsoft.github.io/monaco-editor/playground.html#customizing-the-appearence-exposed-colors
It just includes an iframe -.-
not a good way,dirty hackQAQ
Keeping this thread alive after 5 years. This is still needed. I could even take a CSS guide on which properties to manually override.