@@ -2,9 +2,10 @@ import { EditorApi, InfoviewApi } from "@leanprover/infoview-api"
2
2
import { InfoWebviewFactory , InfoWebview } from "./vscode-lean4/vscode-lean4/src/infoview"
3
3
import { Rpc } from "./vscode-lean4/vscode-lean4/src/rpc"
4
4
import { ViewColumn , Disposable , EventEmitter } from "vscode"
5
- import { IColorTheme , IThemeService } from "vscode/services"
5
+ import { IColorTheme , IConfigurationService , IThemeService , IEditorOptions } from "vscode/services"
6
6
import * as colorUtils from 'vscode/vscode/vs/platform/theme/common/colorUtils' ;
7
7
import { ColorScheme } from 'vscode/vscode/vs/platform/theme/common/theme' ;
8
+ import * as editorOptions from 'vscode/vscode/vs/editor/common/config/editorOptions' ;
8
9
9
10
export class IFrameInfoWebview implements InfoWebview {
10
11
@@ -33,7 +34,7 @@ export class IFrameInfoWebviewFactory implements InfoWebviewFactory {
33
34
private infoviewElement : HTMLElement
34
35
private iframe : HTMLIFrameElement
35
36
36
- constructor ( private themeService : IThemeService ) { }
37
+ constructor ( private themeService : IThemeService , private configurationService : IConfigurationService , private fontFile : FontFace ) { }
37
38
38
39
setInfoviewElement ( infoviewElement : HTMLElement ) {
39
40
this . infoviewElement = infoviewElement
@@ -80,13 +81,45 @@ export class IFrameInfoWebviewFactory implements InfoWebviewFactory {
80
81
private updateCssVars ( ) {
81
82
const theme = this . themeService . getColorTheme ( ) ;
82
83
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 ) => {
84
87
const color = theme . getColor ( entry . id ) ;
85
88
if ( color ) {
86
- documentStyle ?. setProperty ( '-- vscode-' + entry . id . replace ( '.' , '-' ) , color . toString ( ) ) ;
89
+ colors [ ' vscode-' + entry . id . replace ( '.' , '-' ) ] = color . toString ( ) ;
87
90
}
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 ] ) ;
88
116
}
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 ) ;
90
123
}
91
124
92
125
private apiThemeClassName ( theme : IColorTheme ) {
@@ -113,7 +146,6 @@ export class IFrameInfoWebviewFactory implements InfoWebviewFactory {
113
146
color: var(--vscode-editor-foreground);
114
147
}
115
148
</style>
116
- <link rel="stylesheet" href="${ new URL ( './vscode.css' , import . meta. url ) } ">
117
149
<link rel="stylesheet" href="${ new URL ( '../node_modules/@leanprover/infoview/dist/index.css' , import . meta. url ) } ">
118
150
</head>
119
151
<body>
0 commit comments