Set className and textContent in the dynamic style element 'monaco-colors' before appended

This commit is contained in:
csu-feizao
2023-03-13 15:56:55 +08:00
committed by 洪兴华
parent 83fe8e03fb
commit d80c5b274e
2 changed files with 10 additions and 7 deletions
+2 -1
View File
@@ -691,10 +691,11 @@ export function getActiveElement(): Element | null {
return result;
}
export function createStyleSheet(container: HTMLElement = document.getElementsByTagName('head')[0]): HTMLStyleElement {
export function createStyleSheet(container: HTMLElement = document.getElementsByTagName('head')[0], beforeAppend?: (style: HTMLStyleElement) => void): HTMLStyleElement {
const style = document.createElement('style');
style.type = 'text/css';
style.media = 'screen';
beforeAppend?.(style);
container.appendChild(style);
return style;
}
@@ -274,18 +274,20 @@ export class StandaloneThemeService extends Disposable implements IStandaloneThe
private _registerRegularEditorContainer(): IDisposable {
if (!this._globalStyleElement) {
this._globalStyleElement = dom.createStyleSheet();
this._globalStyleElement.className = 'monaco-colors';
this._globalStyleElement.textContent = this._allCSS;
this._globalStyleElement = dom.createStyleSheet(undefined, style => {
style.className = 'monaco-colors';
style.textContent = this._allCSS;
});
this._styleElements.push(this._globalStyleElement);
}
return Disposable.None;
}
private _registerShadowDomContainer(domNode: HTMLElement): IDisposable {
const styleElement = dom.createStyleSheet(domNode);
styleElement.className = 'monaco-colors';
styleElement.textContent = this._allCSS;
const styleElement = dom.createStyleSheet(domNode, style => {
style.className = 'monaco-colors';
style.textContent = this._allCSS;
});
this._styleElements.push(styleElement);
return {
dispose: () => {