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

Can not create two editor with different theme

Open WangYuLue opened this issue 5 years ago • 12 comments

monaco-editor version: 0.14.2 & 0.18.1 Browser: chrome 69 OS: macOS Mojave 10.14 Playground code that reproduces the issue:

monaco.editor.create(document.getElementById("container"), {
	value: "function hello() {\n\talert('Hello world!');\n}",
        theme: 'vs-light',
	language: "javascript"
});


monaco.editor.create(document.getElementById("container1"), {
	value: "function hello() {\n\talert('Hello Monaco!');\n}",
        theme: 'vs-dark',
	language: "javascript"
});
<div id="container" style="height:30%;"></div>
<hr>
<div id="container1" style="height:30%;"></div>

屏幕快照 2019-12-18 下午7 45 58

I set dark theme and light theme, but all show dark theme

WangYuLue avatar Dec 18 '19 11:12 WangYuLue

You can try.. const ed1 = monaco.editor const ed2 = monaco.editor // Other monaco ed1.create(...) ed2.create(...)

yunliang-ding avatar Jan 21 '20 04:01 yunliang-ding

I can report the same thing, @yunliang-ding your solution didn't seem to work. In my case I am actually calling create at two different times:

exports.create_ = function (monaco, nodeId, languageId, themeName) {
  console.log(nodeId);
  console.log(languageId);
  console.log(themeName);
  const editor = monaco.editor.create(nodeId, {
    value: [
      'Close'
    ].join('\n'),
    language: languageId,
    theme: themeName,
  });
  return editor;
}

Note here that monaco references the same object coming from webpack entry point:

import * as monaco from 'monaco-editor/esm/vs/editor/editor.api';
global.monaco = monaco;

This is a real issue for me now 😢

shmish111 avatar Apr 06 '20 19:04 shmish111

Also note that all other things that depend on languageId seem to work just fine (TokensProvider, DocumentFormattingEditProvider etc). For example, for one of the editors I provide a DocumentFormattingEditProvider but for the other I do not. If I press f1 on each editor then only 1 has access to "Format Document" as expected.

shmish111 avatar Apr 06 '20 19:04 shmish111

Ah, I discovered that setTheme exists but it is a global thing: https://microsoft.github.io/monaco-editor/api/modules/monaco.editor.html#settheme

so this issue then is a feature request to move setTheme to https://microsoft.github.io/monaco-editor/api/interfaces/monaco.editor.istandalonecodeeditor.html or some other way of achieving the same thing.

shmish111 avatar Apr 06 '20 19:04 shmish111

+1 on this, could be cool (not critical though)

bodinsamuel avatar Jun 23 '20 07:06 bodinsamuel

+1 on this, has any solution?

10229428 avatar Jul 15 '20 01:07 10229428

I've been changing the theme every time I switch, not ideal though and it only works for me since I never have 2 editors on screen at the same time

shmish111 avatar Jul 15 '20 15:07 shmish111

+1 on this

zuiidea avatar Sep 22 '20 03:09 zuiidea

+1 on this

SPERONIS avatar Sep 06 '21 12:09 SPERONIS

+1 on this

fomenyesu avatar Sep 09 '21 17:09 fomenyesu

the same problem, how to solve?

14glwu avatar Jul 28 '22 10:07 14glwu

Is it planned to be fixed?

Oleksandr-Silin avatar Aug 04 '22 16:08 Oleksandr-Silin

Have you guys found any workarounds?

joaohenrifranco avatar Sep 22 '22 19:09 joaohenrifranco

how to solve?

keyon17 avatar Mar 05 '23 21:03 keyon17

I am also here to look for solutions. Didn't work for me at v0.36.1. Do we get a fix now?

praylee avatar Mar 30 '23 15:03 praylee

This is related. https://github.com/Microsoft/monaco-editor/issues/338#issuecomment-1553847664

zerobytes avatar May 19 '23 00:05 zerobytes

/duplicate #338

hediet avatar May 26 '23 16:05 hediet