From d80c5b274ea46baed43413207c6f0561868899e8 Mon Sep 17 00:00:00 2001 From: csu-feizao <2564150105@qq.com> Date: Fri, 10 Mar 2023 17:44:03 +0800 Subject: [PATCH] Set className and textContent in the dynamic style element 'monaco-colors' before appended --- src/vs/base/browser/dom.ts | 3 ++- .../standalone/browser/standaloneThemeService.ts | 14 ++++++++------ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/vs/base/browser/dom.ts b/src/vs/base/browser/dom.ts index 40fa146233e..e31eedaaabd 100644 --- a/src/vs/base/browser/dom.ts +++ b/src/vs/base/browser/dom.ts @@ -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; } diff --git a/src/vs/editor/standalone/browser/standaloneThemeService.ts b/src/vs/editor/standalone/browser/standaloneThemeService.ts index 669791cecee..ec49af70ece 100644 --- a/src/vs/editor/standalone/browser/standaloneThemeService.ts +++ b/src/vs/editor/standalone/browser/standaloneThemeService.ts @@ -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: () => {