monaco-editor icon indicating copy to clipboard operation
monaco-editor copied to clipboard

Changing theme in one editor should change all editors

Open fzafiroski opened this issue 7 years ago • 43 comments

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.

fzafiroski avatar Jan 24 '17 13:01 fzafiroski

It is currently not possible to have two editors have different themes.

alexdima avatar Jan 24 '17 15:01 alexdima

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.

fzafiroski avatar Jan 24 '17 15:01 fzafiroski

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: ... });

alexdima avatar Jan 25 '17 13:01 alexdima

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.

fzafiroski avatar Jan 25 '17 13:01 fzafiroski

Why is not possible to have multiple editors of different themes?

waltonseymour avatar Feb 28 '17 23:02 waltonseymour

-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.

jrshust avatar Feb 28 '17 23:02 jrshust

@alexandrudima is this problem solved? I have the same problem in "monaco-editor": "^0.10.1",.

liyann avatar Apr 08 '18 03:04 liyann

Any updates on the issue?

antikus avatar Aug 31 '18 02:08 antikus

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!

tevfik6 avatar Aug 31 '18 12:08 tevfik6

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.

alexdima avatar Aug 31 '18 12:08 alexdima

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!

tevfik6 avatar Aug 31 '18 12:08 tevfik6

Could colors of tokens be represented as CSS classes, so applying different colors can be achieved by applying different CSS rules?

yfwz100 avatar Mar 11 '19 09:03 yfwz100

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.

cancerberoSgx avatar Jun 01 '19 23:06 cancerberoSgx

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.

image

Originally It looks like...

image

Nishchit14 avatar Jul 25 '20 17:07 Nishchit14

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).

hediet avatar Aug 06 '20 15:08 hediet

sad :(

ry7791 avatar Aug 07 '20 02:08 ry7791

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

yingchen518 avatar Sep 25 '20 06:09 yingchen518

The second editor is in an <iframe>.

alexdima avatar Sep 25 '20 07:09 alexdima

@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?

taikulawo avatar Sep 28 '20 10:09 taikulawo

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 avatar Sep 28 '20 10:09 hediet

@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. :(

taikulawo avatar Sep 30 '20 09:09 taikulawo

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:

image

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);
}
image

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.

zebateira avatar May 13 '21 11:05 zebateira

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:

image

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);
}
image

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.

sauravgupta2800 avatar Jun 19 '21 10:06 sauravgupta2800

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.

erahhal avatar Oct 25 '21 16:10 erahhal

unexpected, it's a very strange behavior for a standalone editor library.

iahu avatar Oct 26 '21 05:10 iahu

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 -.-

JPVenson avatar Nov 17 '21 20:11 JPVenson

still have this problem, i just wanna use a editor to be a terminal log box, and set a theme different from main editor

liuyike98 avatar Dec 23 '21 10:12 liuyike98

Hi, is there an update on this?

AlmogBaku avatar Jan 03 '22 15:01 AlmogBaku

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

xiaoqingb avatar Jun 13 '22 11:06 xiaoqingb

Keeping this thread alive after 5 years. This is still needed. I could even take a CSS guide on which properties to manually override.

janarvaez avatar Aug 05 '22 08:08 janarvaez