@@ -42,7 +42,7 @@ import { ILink, LinkedText } from 'vs/base/common/linkedText';
42
42
import { Button } from 'vs/base/browser/ui/button/button' ;
43
43
import { Link } from 'vs/platform/opener/browser/link' ;
44
44
import { renderFormattedText } from 'vs/base/browser/formattedTextRenderer' ;
45
- import { IWebviewService } from 'vs/workbench/contrib/webview/browser/webview' ;
45
+ import { IWebviewElement , IWebviewService } from 'vs/workbench/contrib/webview/browser/webview' ;
46
46
import { ILanguageService } from 'vs/editor/common/languages/language' ;
47
47
import { IExtensionService } from 'vs/workbench/services/extensions/common/extensions' ;
48
48
import { generateUuid } from 'vs/base/common/uuid' ;
@@ -128,6 +128,7 @@ export class GettingStartedPage extends EditorPane {
128
128
private dispatchListeners : DisposableStore = new DisposableStore ( ) ;
129
129
private stepDisposables : DisposableStore = new DisposableStore ( ) ;
130
130
private detailsPageDisposables : DisposableStore = new DisposableStore ( ) ;
131
+ private mediaDisposables : DisposableStore = new DisposableStore ( ) ;
131
132
132
133
// Ensure that the these are initialized before use.
133
134
// Currently initialized before use in buildCategoriesSlide and scrollToCategory
@@ -158,6 +159,7 @@ export class GettingStartedPage extends EditorPane {
158
159
private categoriesSlide ! : HTMLElement ;
159
160
private stepsContent ! : HTMLElement ;
160
161
private stepMediaComponent ! : HTMLElement ;
162
+ private webview ! : IWebviewElement ;
161
163
162
164
private layoutMarkdown : ( ( ) => void ) | undefined ;
163
165
@@ -494,6 +496,7 @@ export class GettingStartedPage extends EditorPane {
494
496
}
495
497
496
498
private currentMediaComponent : string | undefined = undefined ;
499
+ private currentMediaType : string | undefined = undefined ;
497
500
private async buildMediaComponent ( stepId : string ) {
498
501
if ( ! this . currentWalkthrough ) {
499
502
throw Error ( 'no walkthrough selected' ) ;
@@ -507,11 +510,29 @@ export class GettingStartedPage extends EditorPane {
507
510
508
511
this . stepDisposables . add ( {
509
512
dispose : ( ) => {
510
- clearNode ( this . stepMediaComponent ) ;
511
513
this . currentMediaComponent = undefined ;
512
514
}
513
515
} ) ;
514
516
517
+ if ( this . currentMediaType !== stepToExpand . media . type ) {
518
+
519
+ this . currentMediaType = stepToExpand . media . type ;
520
+
521
+ this . mediaDisposables . add ( toDisposable ( ( ) => {
522
+ this . currentMediaType = undefined ;
523
+ } ) ) ;
524
+
525
+ clearNode ( this . stepMediaComponent ) ;
526
+
527
+ if ( stepToExpand . media . type === 'svg' ) {
528
+ this . webview = this . mediaDisposables . add ( this . webviewService . createWebviewElement ( { title : undefined , options : { disableServiceWorker : true } , contentOptions : { } , extension : undefined } ) ) ;
529
+ this . webview . mountTo ( this . stepMediaComponent ) ;
530
+ } else if ( stepToExpand . media . type === 'markdown' ) {
531
+ this . webview = this . mediaDisposables . add ( this . webviewService . createWebviewElement ( { options : { } , contentOptions : { localResourceRoots : [ stepToExpand . media . root ] , allowScripts : true } , title : '' , extension : undefined } ) ) ;
532
+ this . webview . mountTo ( this . stepMediaComponent ) ;
533
+ }
534
+ }
535
+
515
536
if ( stepToExpand . media . type === 'image' ) {
516
537
517
538
this . stepsContent . classList . add ( 'image' ) ;
@@ -542,10 +563,7 @@ export class GettingStartedPage extends EditorPane {
542
563
this . stepsContent . classList . remove ( 'markdown' ) ;
543
564
544
565
const media = stepToExpand . media ;
545
- const webview = this . stepDisposables . add ( this . webviewService . createWebviewElement ( { title : undefined , options : { } , contentOptions : { } , extension : undefined } ) ) ;
546
- webview . mountTo ( this . stepMediaComponent ) ;
547
-
548
- webview . setHtml ( await this . detailsRenderer . renderSVG ( media . path ) ) ;
566
+ this . webview . setHtml ( await this . detailsRenderer . renderSVG ( media . path ) ) ;
549
567
550
568
let isDisposed = false ;
551
569
this . stepDisposables . add ( toDisposable ( ( ) => { isDisposed = true ; } ) ) ;
@@ -554,7 +572,7 @@ export class GettingStartedPage extends EditorPane {
554
572
// Render again since color vars change
555
573
const body = await this . detailsRenderer . renderSVG ( media . path ) ;
556
574
if ( ! isDisposed ) { // Make sure we weren't disposed of in the meantime
557
- webview . setHtml ( body ) ;
575
+ this . webview . setHtml ( body ) ;
558
576
}
559
577
} ) ) ;
560
578
@@ -569,7 +587,7 @@ export class GettingStartedPage extends EditorPane {
569
587
}
570
588
} ) ) ;
571
589
572
- this . stepDisposables . add ( webview . onDidClickLink ( link => {
590
+ this . stepDisposables . add ( this . webview . onDidClickLink ( link => {
573
591
if ( matchesScheme ( link , Schemas . https ) || matchesScheme ( link , Schemas . http ) || ( matchesScheme ( link , Schemas . command ) ) ) {
574
592
this . openerService . open ( link , { allowCommands : true } ) ;
575
593
}
@@ -583,11 +601,8 @@ export class GettingStartedPage extends EditorPane {
583
601
584
602
const media = stepToExpand . media ;
585
603
586
- const webview = this . stepDisposables . add ( this . webviewService . createWebviewElement ( { options : { } , contentOptions : { localResourceRoots : [ media . root ] , allowScripts : true } , title : '' , extension : undefined } ) ) ;
587
- webview . mountTo ( this . stepMediaComponent ) ;
588
-
589
604
const rawHTML = await this . detailsRenderer . renderMarkdown ( media . path , media . base ) ;
590
- webview . setHtml ( rawHTML ) ;
605
+ this . webview . setHtml ( rawHTML ) ;
591
606
592
607
const serializedContextKeyExprs = rawHTML . match ( / c h e c k e d - o n = \" ( [ ^ ' ] [ ^ " ] * ) \" / g) ?. map ( attr => attr . slice ( 'checked-on="' . length , - 1 )
593
608
. replace ( / & # 3 9 ; / g, '\'' )
@@ -596,7 +611,7 @@ export class GettingStartedPage extends EditorPane {
596
611
const postTrueKeysMessage = ( ) => {
597
612
const enabledContextKeys = serializedContextKeyExprs ?. filter ( expr => this . contextService . contextMatchesRules ( ContextKeyExpr . deserialize ( expr ) ) ) ;
598
613
if ( enabledContextKeys ) {
599
- webview . postMessage ( {
614
+ this . webview . postMessage ( {
600
615
enabledContextKeys
601
616
} ) ;
602
617
}
@@ -614,7 +629,7 @@ export class GettingStartedPage extends EditorPane {
614
629
let isDisposed = false ;
615
630
this . stepDisposables . add ( toDisposable ( ( ) => { isDisposed = true ; } ) ) ;
616
631
617
- this . stepDisposables . add ( webview . onDidClickLink ( link => {
632
+ this . stepDisposables . add ( this . webview . onDidClickLink ( link => {
618
633
if ( matchesScheme ( link , Schemas . https ) || matchesScheme ( link , Schemas . http ) || ( matchesScheme ( link , Schemas . command ) ) ) {
619
634
this . openerService . open ( link , { allowCommands : true } ) ;
620
635
}
@@ -625,7 +640,7 @@ export class GettingStartedPage extends EditorPane {
625
640
this . stepDisposables . add ( this . themeService . onDidColorThemeChange ( async ( ) => {
626
641
const body = await this . detailsRenderer . renderMarkdown ( media . path , media . base ) ;
627
642
if ( ! isDisposed ) { // Make sure we weren't disposed of in the meantime
628
- webview . setHtml ( body ) ;
643
+ this . webview . setHtml ( body ) ;
629
644
postTrueKeysMessage ( ) ;
630
645
}
631
646
} ) ) ;
@@ -635,7 +650,7 @@ export class GettingStartedPage extends EditorPane {
635
650
636
651
this . layoutMarkdown = ( ) => {
637
652
layoutDelayer . trigger ( ( ) => {
638
- webview . postMessage ( { layoutMeNow : true } ) ;
653
+ this . webview . postMessage ( { layoutMeNow : true } ) ;
639
654
} ) ;
640
655
} ;
641
656
@@ -644,16 +659,13 @@ export class GettingStartedPage extends EditorPane {
644
659
645
660
postTrueKeysMessage ( ) ;
646
661
647
- this . stepDisposables . add ( webview . onMessage ( e => {
662
+ this . stepDisposables . add ( this . webview . onMessage ( e => {
648
663
const message : string = e . message as string ;
649
664
if ( message . startsWith ( 'command:' ) ) {
650
665
this . openerService . open ( message , { allowCommands : true } ) ;
651
666
} else if ( message . startsWith ( 'setTheme:' ) ) {
652
667
this . configurationService . updateValue ( ThemeSettings . COLOR_THEME , message . slice ( 'setTheme:' . length ) , ConfigurationTarget . USER ) ;
653
- } else if ( message === 'unloaded' ) {
654
- this . buildMediaComponent ( stepId ) ;
655
- }
656
- else {
668
+ } else {
657
669
console . error ( 'Unexpected message' , message ) ;
658
670
}
659
671
} ) ) ;
@@ -1139,6 +1151,12 @@ export class GettingStartedPage extends EditorPane {
1139
1151
this . featuredExtensionsList ?. layout ( size ) ;
1140
1152
this . recentlyOpenedList ?. layout ( size ) ;
1141
1153
1154
+ if ( this . editorInput . selectedStep && this . currentMediaType ) {
1155
+ this . mediaDisposables . clear ( ) ;
1156
+ this . stepDisposables . clear ( ) ;
1157
+ this . buildMediaComponent ( this . editorInput . selectedStep ) ;
1158
+ }
1159
+
1142
1160
this . layoutMarkdown ?.( ) ;
1143
1161
1144
1162
this . container . classList . toggle ( 'height-constrained' , size . height <= 600 ) ;
@@ -1352,6 +1370,7 @@ export class GettingStartedPage extends EditorPane {
1352
1370
} ) ;
1353
1371
1354
1372
this . detailsPageDisposables . clear ( ) ;
1373
+ this . mediaDisposables . clear ( ) ;
1355
1374
1356
1375
const category = this . gettingStartedCategories . find ( category => category . id === categoryID ) ;
1357
1376
if ( ! category ) {
0 commit comments