@@ -1489,11 +1489,28 @@ async function webviewPreloads(ctx: PreloadContext) {
1489
1489
this . _renderers . get ( rendererId ) ?. disposeOutputItem ( outputId ) ;
1490
1490
}
1491
1491
1492
- public async render ( info : rendererApi . OutputItem , element : HTMLElement , signal : AbortSignal ) : Promise < void > {
1493
- const renderers = Array . from ( this . _renderers . values ( ) )
1494
- . filter ( ( renderer ) => renderer . data . mimeTypes . includes ( info . mime ) && ! renderer . data . extends ) ;
1492
+ public async render ( info : rendererApi . OutputItem , preferredRendererId : string | undefined , element : HTMLElement , signal : AbortSignal ) : Promise < void > {
1493
+ let renderer : Renderer | undefined ;
1495
1494
1496
- if ( ! renderers . length ) {
1495
+ if ( typeof preferredRendererId === 'string' ) {
1496
+ renderer = Array . from ( this . _renderers . values ( ) )
1497
+ . find ( ( renderer ) => renderer . data . id === preferredRendererId ) ;
1498
+ } else {
1499
+ const renderers = Array . from ( this . _renderers . values ( ) )
1500
+ . filter ( ( renderer ) => renderer . data . mimeTypes . includes ( info . mime ) && ! renderer . data . extends ) ;
1501
+
1502
+ if ( renderers . length ) {
1503
+ // De-prioritize built-in renderers
1504
+ renderers . sort ( ( a , b ) => + a . data . isBuiltin - + b . data . isBuiltin ) ;
1505
+
1506
+ // Use first renderer we find in sorted list
1507
+ renderer = renderers [ 0 ] ;
1508
+ }
1509
+ }
1510
+
1511
+ if ( renderer ) {
1512
+ await renderer . renderOutputItem ( info , element , signal ) ;
1513
+ } else {
1497
1514
const errorContainer = document . createElement ( 'div' ) ;
1498
1515
1499
1516
const error = document . createElement ( 'div' ) ;
@@ -1509,15 +1526,7 @@ async function webviewPreloads(ctx: PreloadContext) {
1509
1526
1510
1527
element . innerText = '' ;
1511
1528
element . appendChild ( errorContainer ) ;
1512
-
1513
- return ;
1514
1529
}
1515
-
1516
- // De-prioritize built-in renderers
1517
- renderers . sort ( ( a , b ) => + a . data . isBuiltin - + b . data . isBuiltin ) ;
1518
-
1519
- // Use first renderer we find in sorted list
1520
- await renderers [ 0 ] . renderOutputItem ( info , element , signal ) ;
1521
1530
}
1522
1531
} ( ) ;
1523
1532
@@ -1874,7 +1883,7 @@ async function webviewPreloads(ctx: PreloadContext) {
1874
1883
const controller = new AbortController ( ) ;
1875
1884
this . renderTaskAbort = controller ;
1876
1885
try {
1877
- await renderers . render ( this . outputItem , this . element , this . renderTaskAbort . signal ) ;
1886
+ await renderers . render ( this . outputItem , undefined , this . element , this . renderTaskAbort . signal ) ;
1878
1887
} finally {
1879
1888
if ( this . renderTaskAbort === controller ) {
1880
1889
this . renderTaskAbort = undefined ;
@@ -2001,7 +2010,7 @@ async function webviewPreloads(ctx: PreloadContext) {
2001
2010
2002
2011
public async renderOutputElement ( data : webviewMessages . ICreationRequestMessage , preloadErrors : ReadonlyArray < Error | undefined > , signal : AbortSignal ) {
2003
2012
const outputElement = this . createOutputElement ( data ) ;
2004
- await outputElement . render ( data . content , preloadErrors , signal ) ;
2013
+ await outputElement . render ( data . content , data . rendererId , preloadErrors , signal ) ;
2005
2014
2006
2015
// don't hide until after this step so that the height is right
2007
2016
outputElement . element . style . visibility = data . initiallyHidden ? 'hidden' : '' ;
@@ -2132,6 +2141,7 @@ async function webviewPreloads(ctx: PreloadContext) {
2132
2141
public readonly element : HTMLElement ;
2133
2142
private _content ?: {
2134
2143
readonly content : webviewMessages . ICreationContent ;
2144
+ readonly preferredRendererId : string | undefined ;
2135
2145
readonly preloadErrors : ReadonlyArray < Error | undefined > ;
2136
2146
} ;
2137
2147
private hasResizeObserver = false ;
@@ -2164,11 +2174,11 @@ async function webviewPreloads(ctx: PreloadContext) {
2164
2174
this . renderTaskAbort = undefined ;
2165
2175
}
2166
2176
2167
- public async render ( content : webviewMessages . ICreationContent , preloadErrors : ReadonlyArray < Error | undefined > , signal ?: AbortSignal ) {
2177
+ public async render ( content : webviewMessages . ICreationContent , preferredRendererId : string | undefined , preloadErrors : ReadonlyArray < Error | undefined > , signal ?: AbortSignal ) {
2168
2178
this . renderTaskAbort ?. abort ( ) ;
2169
2179
this . renderTaskAbort = undefined ;
2170
2180
2171
- this . _content = { content, preloadErrors } ;
2181
+ this . _content = { content, preferredRendererId , preloadErrors } ;
2172
2182
if ( content . type === 0 /* RenderOutputType.Html */ ) {
2173
2183
const trustedHtml = ttPolicy ?. createHTML ( content . htmlContent ) ?? content . htmlContent ;
2174
2184
this . element . innerHTML = trustedHtml as string ;
@@ -2186,7 +2196,7 @@ async function webviewPreloads(ctx: PreloadContext) {
2186
2196
signal ?. addEventListener ( 'abort' , ( ) => controller . abort ( ) ) ;
2187
2197
2188
2198
try {
2189
- await renderers . render ( item , this . element , controller . signal ) ;
2199
+ await renderers . render ( item , preferredRendererId , this . element , controller . signal ) ;
2190
2200
} finally {
2191
2201
if ( this . renderTaskAbort === controller ) {
2192
2202
this . renderTaskAbort = undefined ;
@@ -2229,13 +2239,13 @@ async function webviewPreloads(ctx: PreloadContext) {
2229
2239
2230
2240
public rerender ( ) {
2231
2241
if ( this . _content ) {
2232
- this . render ( this . _content . content , this . _content . preloadErrors ) ;
2242
+ this . render ( this . _content . content , this . _content . preferredRendererId , this . _content . preloadErrors ) ;
2233
2243
}
2234
2244
}
2235
2245
2236
2246
public updateAndRerender ( content : webviewMessages . ICreationContent ) {
2237
2247
if ( this . _content ) {
2238
- this . _content = { content, preloadErrors : this . _content . preloadErrors } ;
2248
+ this . _content = { content, preferredRendererId : this . _content . preferredRendererId , preloadErrors : this . _content . preloadErrors } ;
2239
2249
this . rerender ( ) ;
2240
2250
}
2241
2251
}
0 commit comments