Skip to content

Commit a9809eb

Browse files
committed
more css vars
1 parent fe9ff23 commit a9809eb

File tree

4 files changed

+47
-21
lines changed

4 files changed

+47
-21
lines changed

Diff for: demo/package-lock.json

-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: src/infowebview.ts

+38-6
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ import { EditorApi, InfoviewApi } from "@leanprover/infoview-api"
22
import { InfoWebviewFactory, InfoWebview } from "./vscode-lean4/vscode-lean4/src/infoview"
33
import { Rpc } from "./vscode-lean4/vscode-lean4/src/rpc"
44
import { ViewColumn, Disposable, EventEmitter } from "vscode"
5-
import { IColorTheme, IThemeService } from "vscode/services"
5+
import { IColorTheme, IConfigurationService, IThemeService, IEditorOptions } from "vscode/services"
66
import * as colorUtils from 'vscode/vscode/vs/platform/theme/common/colorUtils';
77
import { ColorScheme } from 'vscode/vscode/vs/platform/theme/common/theme';
8+
import * as editorOptions from 'vscode/vscode/vs/editor/common/config/editorOptions';
89

910
export class IFrameInfoWebview implements InfoWebview {
1011

@@ -33,7 +34,7 @@ export class IFrameInfoWebviewFactory implements InfoWebviewFactory {
3334
private infoviewElement: HTMLElement
3435
private iframe: HTMLIFrameElement
3536

36-
constructor(private themeService: IThemeService) { }
37+
constructor(private themeService: IThemeService, private configurationService: IConfigurationService, private fontFile: FontFace) { }
3738

3839
setInfoviewElement(infoviewElement: HTMLElement) {
3940
this.infoviewElement = infoviewElement
@@ -80,13 +81,45 @@ export class IFrameInfoWebviewFactory implements InfoWebviewFactory {
8081
private updateCssVars() {
8182
const theme = this.themeService.getColorTheme();
8283
const documentStyle = this.iframe.contentDocument?.documentElement.style;
83-
for (const entry of ((colorUtils as any).getColorRegistry().getColors() as Array<{id:string}>)) {
84+
const colors: Array<{id:string}> = (colorUtils as any).getColorRegistry().getColors()
85+
86+
const exportedColors = colors.reduce<Record<string, string>>((colors, entry) => {
8487
const color = theme.getColor(entry.id);
8588
if (color) {
86-
documentStyle?.setProperty('--vscode-' + entry.id.replace('.', '-'), color.toString());
89+
colors['vscode-' + entry.id.replace('.', '-')] = color.toString();
8790
}
91+
return colors;
92+
}, {});
93+
94+
const EDITOR_FONT_DEFAULTS = (editorOptions as any).EDITOR_FONT_DEFAULTS
95+
const configuration: any = this.configurationService.getValue<IEditorOptions>('editor');
96+
const editorFontFamily = configuration.fontFamily || EDITOR_FONT_DEFAULTS.fontFamily;
97+
const editorFontWeight = configuration.fontWeight || EDITOR_FONT_DEFAULTS.fontWeight;
98+
const editorFontSize = configuration.fontSize || EDITOR_FONT_DEFAULTS.fontSize;
99+
const linkUnderlines = this.configurationService.getValue('accessibility.underlineLinks');
100+
101+
const styles: {[id: string]: string} = {
102+
'vscode-font-family': '\'Droid Sans Mono\', Consolas, Menlo, Monaco, \'Courier New\', monospace',
103+
'vscode-font-weight': 'normal',
104+
'vscode-font-size': '13px',
105+
'vscode-editor-font-family': editorFontFamily,
106+
'vscode-editor-font-weight': editorFontWeight,
107+
'vscode-editor-font-size': editorFontSize + 'px',
108+
'text-link-decoration': linkUnderlines ? 'underline' : 'none',
109+
...exportedColors
110+
};
111+
112+
console.log(styles)
113+
114+
for (const id in styles) {
115+
documentStyle?.setProperty(`--${id}`, styles[id]);
88116
}
89-
this.iframe.contentDocument?.documentElement.setAttribute('class', this.apiThemeClassName(theme))
117+
118+
documentStyle?.setProperty('font-family', '-apple-system,BlinkMacSystemFont,Segoe WPC,Segoe UI,HelveticaNeue-Light,system-ui,Ubuntu,Droid Sans,sans-serif')
119+
120+
this.iframe.contentDocument?.documentElement.setAttribute('class', `${this.apiThemeClassName(theme)}`)
121+
122+
this.iframe.contentDocument?.fonts.add(this.fontFile);
90123
}
91124

92125
private apiThemeClassName(theme: IColorTheme) {
@@ -113,7 +146,6 @@ export class IFrameInfoWebviewFactory implements InfoWebviewFactory {
113146
color: var(--vscode-editor-foreground);
114147
}
115148
</style>
116-
<link rel="stylesheet" href="${new URL('./vscode.css', import.meta.url)}">
117149
<link rel="stylesheet" href="${new URL('../node_modules/@leanprover/infoview/dist/index.css', import.meta.url)}">
118150
</head>
119151
<body>

Diff for: src/leanmonaco.ts

+9-7
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { IFrameInfoWebviewFactory } from './infowebview'
99
import { setupMonacoClient } from './monacoleanclient';
1010
import { checkLean4ProjectPreconditions } from './preconditions'
1111
import { ExtUri } from './vscode-lean4/vscode-lean4/src/utils/exturi';
12-
import { initialize, getService, IThemeService } from 'vscode/services';
12+
import { initialize, getService, IThemeService, IConfigurationService } from 'vscode/services';
1313
import getConfigurationServiceOverride, { updateUserConfiguration, initUserConfiguration } from '@codingame/monaco-vscode-configuration-service-override';
1414
import getTextmateServiceOverride from '@codingame/monaco-vscode-textmate-service-override'
1515
import getThemeServiceOverride from '@codingame/monaco-vscode-theme-service-override'
@@ -113,6 +113,7 @@ export class LeanMonaco {
113113
if (this.disposed) return;
114114

115115
const themeService = await getService(IThemeService)
116+
const configurationService = await getService(IConfigurationService)
116117

117118
if (this.disposed) return;
118119

@@ -132,17 +133,18 @@ export class LeanMonaco {
132133
)
133134

134135
this.taskGutter = new LeanTaskGutter(this.clientProvider, {asAbsolutePath: (path: string) => Uri.parse(`${new URL('vscode-lean4/vscode-lean4/' + path, import.meta.url)}`),} as any)
135-
136-
this.iframeWebviewFactory = new IFrameInfoWebviewFactory(themeService)
137-
if (this.infoviewEl) this.iframeWebviewFactory.setInfoviewElement(this.infoviewEl)
138-
139-
this.infoProvider = new InfoProvider(this.clientProvider, {language: 'lean4'}, {} as any, this.iframeWebviewFactory)
140-
136+
141137
const fontFile = new FontFace(
142138
"JuliaMono",
143139
`url(${new URL("./JuliaMono-Regular.ttf", import.meta.url)})`,
144140
);
145141
document.fonts.add(fontFile);
142+
143+
this.iframeWebviewFactory = new IFrameInfoWebviewFactory(themeService, configurationService, fontFile)
144+
if (this.infoviewEl) this.iframeWebviewFactory.setInfoviewElement(this.infoviewEl)
145+
146+
this.infoProvider = new InfoProvider(this.clientProvider, {language: 'lean4'}, {} as any, this.iframeWebviewFactory)
147+
146148
await fontFile.load()
147149

148150
this.updateVSCodeOptions(options.vscode ?? {})

Diff for: src/vscode.css

-7
This file was deleted.

0 commit comments

Comments
 (0)