Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/vs/base/browser/domStylesheets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import { DisposableStore, toDisposable, IDisposable } from '../common/lifecycle.js';
import { autorun, IObservable } from '../common/observable.js';
import { isFirefox } from './browser.js';
import { getWindows, sharedMutationObserver } from './dom.js';
import { mainWindow } from './window.js';

Expand Down Expand Up @@ -97,7 +98,15 @@ function cloneGlobalStyleSheet(globalStylesheet: HTMLStyleElement, globalStylesh
clone.sheet?.insertRule(rule.cssText, clone.sheet?.cssRules.length);
}

disposables.add(sharedMutationObserver.observe(globalStylesheet, disposables, { childList: true })(() => {
let observeInit: MutationObserverInit = { childList: true };
if (isFirefox) {
// Firefox doesn't support observing style tag contents
// As a workaround, also observe the data-version attribute
// that is updated when the content is updated
observeInit = { ...observeInit, attributes: true, attributeFilter: ['data-version'] };
}

disposables.add(sharedMutationObserver.observe(globalStylesheet, disposables, observeInit)(() => {
clone.textContent = globalStylesheet.textContent;
}));

Expand Down
25 changes: 17 additions & 8 deletions src/vs/workbench/services/themes/browser/workbenchThemeService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import { updateColorThemeConfigurationSchemas, updateFileIconThemeConfigurationS
import { ProductIconThemeData, DEFAULT_PRODUCT_ICON_THEME_ID } from './productIconThemeData.js';
import { registerProductIconThemeSchemas } from '../common/productIconThemeSchema.js';
import { ILogService } from '../../../../platform/log/common/log.js';
import { isWeb } from '../../../../base/common/platform.js';
import { isFirefox, isWeb } from '../../../../base/common/platform.js';
import { ColorScheme, ThemeTypeSelector } from '../../../../platform/theme/common/theme.js';
import { IHostColorSchemeService } from '../common/hostColorSchemeService.js';
import { RunOnceScheduler, Sequencer } from '../../../../base/common/async.js';
Expand All @@ -42,6 +42,7 @@ import { getIconsStyleSheet } from '../../../../platform/theme/browser/iconsStyl
import { asCssVariableName, getColorRegistry } from '../../../../platform/theme/common/colorRegistry.js';
import { ILanguageService } from '../../../../editor/common/languages/language.js';
import { mainWindow } from '../../../../base/browser/window.js';
import { generateUuid } from '../../../../base/common/uuid.js';

// implementation

Expand Down Expand Up @@ -793,13 +794,21 @@ class ThemeFileWatcher {
}

function _applyRules(styleSheetContent: string, rulesClassName: string) {
const themeStyles = mainWindow.document.head.getElementsByClassName(rulesClassName);
if (themeStyles.length === 0) {
const elStyle = createStyleSheet();
elStyle.className = rulesClassName;
elStyle.textContent = styleSheetContent;
} else {
(<HTMLStyleElement>themeStyles[0]).textContent = styleSheetContent;
let themeStyle = mainWindow.document.head.getElementsByClassName(rulesClassName).item(0);
if (!themeStyle) {
themeStyle = createStyleSheet();
themeStyle.className = rulesClassName;
}

if (themeStyle.textContent !== styleSheetContent) {
Comment thread
bpasero marked this conversation as resolved.
themeStyle.textContent = styleSheetContent;

if (isFirefox) {
// Firefox doesn't support observing style tag contents
// As a workaround, also update the data-version attribute
// when it changes so it can be observed
themeStyle.setAttribute('data-version', generateUuid());
}
}
}

Expand Down
Loading