@@ -58,6 +58,7 @@ interface EmitterLike<T> {
58
58
interface PreloadStyles {
59
59
readonly outputNodePadding : number ;
60
60
readonly outputNodeLeftPadding : number ;
61
+ readonly tokenizationCss : string ;
61
62
}
62
63
63
64
export interface PreloadOptions {
@@ -98,7 +99,9 @@ async function webviewPreloads(ctx: PreloadContext) {
98
99
const vscode = acquireVsCodeApi ( ) ;
99
100
delete ( globalThis as any ) . acquireVsCodeApi ;
100
101
101
- const tokenizationStyleElement = document . querySelector ( 'style#vscode-tokenization-styles' ) ;
102
+ const tokenizationStyle = new CSSStyleSheet ( ) ;
103
+ tokenizationStyle . replaceSync ( ctx . style . tokenizationCss ) ;
104
+
102
105
const runWhenIdle : ( callback : ( idle : IdleDeadline ) => void , timeout ?: number ) => IDisposable = ( typeof requestIdleCallback !== 'function' || typeof cancelIdleCallback !== 'function' )
103
106
? ( runner ) => {
104
107
setTimeout ( ( ) => {
@@ -1441,9 +1444,7 @@ async function webviewPreloads(ctx: PreloadContext) {
1441
1444
break ;
1442
1445
}
1443
1446
case 'tokenizedStylesChanged' : {
1444
- if ( tokenizationStyleElement ) {
1445
- tokenizationStyleElement . textContent = event . data . css ;
1446
- }
1447
+ tokenizationStyle . replaceSync ( event . data . css ) ;
1447
1448
break ;
1448
1449
}
1449
1450
case 'find' : {
@@ -2059,8 +2060,11 @@ async function webviewPreloads(ctx: PreloadContext) {
2059
2060
}
2060
2061
const trustedHtml = ttPolicy ?. createHTML ( html ) ?? html ;
2061
2062
el . innerHTML = trustedHtml as string ;
2062
- if ( tokenizationStyleElement ) {
2063
- el . insertAdjacentElement ( 'beforebegin' , tokenizationStyleElement . cloneNode ( true ) as HTMLElement ) ;
2063
+ const root = el . getRootNode ( ) ;
2064
+ if ( root instanceof ShadowRoot ) {
2065
+ if ( ! root . adoptedStyleSheets . includes ( tokenizationStyle ) ) {
2066
+ root . adoptedStyleSheets . push ( tokenizationStyle ) ;
2067
+ }
2064
2068
}
2065
2069
}
2066
2070
0 commit comments