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

Expose theme name in webviews #98128

Merged
merged 2 commits into from May 20, 2020
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
Expand Up @@ -42,6 +42,8 @@ suite('TokenizationSupport2Adapter', () => {
}
public getColorTheme(): IStandaloneTheme {
return {
label: 'mock',

tokenTheme: new MockTokenTheme(),

themeName: LIGHT,
Expand Down
3 changes: 3 additions & 0 deletions src/vs/platform/theme/common/themeService.ts
Expand Up @@ -87,8 +87,11 @@ export interface ITokenStyle {
}

export interface IColorTheme {

readonly type: ThemeType;

readonly label: string;

/**
* Resolves the color of the given color identifier. If the theme does not
* specify the color, the default color is returned unless <code>useDefault</code> is set to false.
Expand Down
2 changes: 2 additions & 0 deletions src/vs/platform/theme/test/common/testThemeService.ts
Expand Up @@ -9,6 +9,8 @@ import { Color } from 'vs/base/common/color';

export class TestColorTheme implements IColorTheme {

public readonly label = 'test';

constructor(private colors: { [id: string]: string; } = {}, public type = DARK) {
}

Expand Down
Expand Up @@ -270,8 +270,8 @@ export abstract class BaseWebview<T extends HTMLElement> extends Disposable {
}

protected style(): void {
const { styles, activeTheme } = this.webviewThemeDataProvider.getWebviewThemeData();
this._send('styles', { styles, activeTheme });
const { styles, activeTheme, themeLabel } = this.webviewThemeDataProvider.getWebviewThemeData();
this._send('styles', { styles, activeTheme, themeName: themeLabel });
}

protected handleFocusChange(isFocused: boolean): void {
Expand Down
6 changes: 5 additions & 1 deletion src/vs/workbench/contrib/webview/browser/pre/main.js
Expand Up @@ -179,7 +179,7 @@
let pendingMessages = [];

const initData = {
initialScrollProgress: undefined
initialScrollProgress: undefined,
};


Expand All @@ -195,6 +195,9 @@
if (body) {
body.classList.remove('vscode-light', 'vscode-dark', 'vscode-high-contrast');
body.classList.add(initData.activeTheme);

body.dataset.vscodeThemeKind = initData.activeTheme;
body.dataset.vscodeThemeName = initData.themeName || '';
}

if (initData.styles) {
Expand Down Expand Up @@ -383,6 +386,7 @@
host.onMessage('styles', (_event, data) => {
initData.styles = data.styles;
initData.activeTheme = data.activeTheme;
initData.themeName = data.themeName;

const target = getActiveFrame();
if (!target) {
Expand Down
3 changes: 2 additions & 1 deletion src/vs/workbench/contrib/webview/common/themeing.ts
Expand Up @@ -13,6 +13,7 @@ import { Emitter } from 'vs/base/common/event';

interface WebviewThemeData {
readonly activeTheme: string;
readonly themeLabel: string;
readonly styles: { readonly [key: string]: string | number; };
}

Expand Down Expand Up @@ -73,7 +74,7 @@ export class WebviewThemeDataProvider extends Disposable {
};

const activeTheme = ApiThemeClassName.fromTheme(theme);
return { styles, activeTheme };
return { styles, activeTheme, themeLabel: theme.label, };
}

private reset() {
Expand Down