@@ -58,6 +58,7 @@ interface EmitterLike<T> {
5858interface PreloadStyles {
5959 readonly outputNodePadding : number ;
6060 readonly outputNodeLeftPadding : number ;
61+ readonly tokenizationCss : string ;
6162}
6263
6364export interface PreloadOptions {
@@ -98,7 +99,9 @@ async function webviewPreloads(ctx: PreloadContext) {
9899 const vscode = acquireVsCodeApi ( ) ;
99100 delete ( globalThis as any ) . acquireVsCodeApi ;
100101
101- const tokenizationStyleElement = document . querySelector ( 'style#vscode-tokenization-styles' ) ;
102+ const tokenizationStyle = new CSSStyleSheet ( ) ;
103+ tokenizationStyle . replaceSync ( ctx . style . tokenizationCss ) ;
104+
102105 const runWhenIdle : ( callback : ( idle : IdleDeadline ) => void , timeout ?: number ) => IDisposable = ( typeof requestIdleCallback !== 'function' || typeof cancelIdleCallback !== 'function' )
103106 ? ( runner ) => {
104107 setTimeout ( ( ) => {
@@ -1441,9 +1444,7 @@ async function webviewPreloads(ctx: PreloadContext) {
14411444 break ;
14421445 }
14431446 case 'tokenizedStylesChanged' : {
1444- if ( tokenizationStyleElement ) {
1445- tokenizationStyleElement . textContent = event . data . css ;
1446- }
1447+ tokenizationStyle . replaceSync ( event . data . css ) ;
14471448 break ;
14481449 }
14491450 case 'find' : {
@@ -2059,8 +2060,11 @@ async function webviewPreloads(ctx: PreloadContext) {
20592060 }
20602061 const trustedHtml = ttPolicy ?. createHTML ( html ) ?? html ;
20612062 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+ }
20642068 }
20652069 }
20662070
0 commit comments