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. :(
Most helpful comment
-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.