Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from Mar 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/vs/base/browser/dom.ts
Expand Up @@ -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;
}
Expand Down
14 changes: 8 additions & 6 deletions src/vs/editor/standalone/browser/standaloneThemeService.ts
Expand Up @@ -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: () => {
Expand Down