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>
pull/149173/head
Alexandru Dima 2022-05-10 17:21:55 +02:00 committed by GitHub
parent b44e3caa96
commit 8fb2dc9c2a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 2 deletions

View File

@ -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) {

View File

@ -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;
}