diff options
author | Alexandru Dima <alexdima@microsoft.com> | 2022-05-10 18:21:55 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-10 18:21:55 +0300 |
commit | 8fb2dc9c2a8f6d7fe3e8c5b56a808f61ea0c5970 (patch) | |
tree | 652544c4dad22c1c22e7381ccd385b7f2e600666 | |
parent | b44e3caa96a801c1ad495090649ddf64c8be3f25 (diff) |
Add high contrast light theme on monaco editor (#149165)
* Register light HC theme
* Do not always use black HC theme
Co-authored-by: Loïc Mangeonjean <loic@codingame.com>
-rw-r--r-- | src/vs/editor/standalone/browser/standaloneThemeService.ts | 13 | ||||
-rw-r--r-- | src/vs/platform/theme/common/theme.ts | 4 |
2 files changed, 15 insertions, 2 deletions
diff --git a/src/vs/editor/standalone/browser/standaloneThemeService.ts b/src/vs/editor/standalone/browser/standaloneThemeService.ts index e5230a0a757..cafca9f55a7 100644 --- a/src/vs/editor/standalone/browser/standaloneThemeService.ts +++ b/src/vs/editor/standalone/browser/standaloneThemeService.ts @@ -16,7 +16,7 @@ import { Registry } from 'vs/platform/registry/common/platform'; import { asCssVariableName, ColorIdentifier, Extensions, IColorRegistry } from 'vs/platform/theme/common/colorRegistry'; import { Extensions as ThemingExtensions, ICssStyleCollector, IFileIconTheme, IProductIconTheme, IThemingRegistry, ITokenStyle } from 'vs/platform/theme/common/themeService'; import { IDisposable, Disposable } from 'vs/base/common/lifecycle'; -import { ColorScheme } from 'vs/platform/theme/common/theme'; +import { ColorScheme, isDark } from 'vs/platform/theme/common/theme'; import { getIconsStyleSheet, UnthemedProductIconTheme } from 'vs/platform/theme/browser/iconsStyleSheet'; const VS_THEME_NAME = 'vs'; @@ -242,6 +242,7 @@ export class StandaloneThemeService extends Disposable implements IStandaloneThe this._knownThemes.set(VS_THEME_NAME, newBuiltInTheme(VS_THEME_NAME)); this._knownThemes.set(VS_DARK_THEME_NAME, newBuiltInTheme(VS_DARK_THEME_NAME)); this._knownThemes.set(HC_BLACK_THEME_NAME, newBuiltInTheme(HC_BLACK_THEME_NAME)); + this._knownThemes.set(HC_LIGHT_THEME_NAME, newBuiltInTheme(HC_LIGHT_THEME_NAME)); const iconsStyleSheet = getIconsStyleSheet(this); @@ -339,10 +340,18 @@ export class StandaloneThemeService extends Disposable implements IStandaloneThe this._updateActualTheme(); } + private getHighContrastTheme() { + if (isDark(this._desiredTheme.type)) { + return HC_BLACK_THEME_NAME; + } else { + return HC_LIGHT_THEME_NAME; + } + } + private _updateActualTheme(): void { const theme = ( this._autoDetectHighContrast && window.matchMedia(`(forced-colors: active)`).matches - ? this._knownThemes.get(HC_BLACK_THEME_NAME)! + ? this._knownThemes.get(this.getHighContrastTheme())! : this._desiredTheme ); if (this._theme === theme) { diff --git a/src/vs/platform/theme/common/theme.ts b/src/vs/platform/theme/common/theme.ts index eabe6ecf497..856b2f12eb5 100644 --- a/src/vs/platform/theme/common/theme.ts +++ b/src/vs/platform/theme/common/theme.ts @@ -16,3 +16,7 @@ export enum ColorScheme { export function isHighContrast(scheme: ColorScheme): boolean { return scheme === ColorScheme.HIGH_CONTRAST_DARK || scheme === ColorScheme.HIGH_CONTRAST_LIGHT; } + +export function isDark(scheme: ColorScheme): boolean { + return scheme === ColorScheme.DARK || scheme === ColorScheme.HIGH_CONTRAST_DARK; +} |