@@ -374,12 +374,55 @@ export class GettingStartedPage extends EditorPane {
374374 StorageTarget . USER ) ;
375375 }
376376
377- private async selectStep ( id : string | undefined , delayFocus = true ) {
378- if ( id && this . editorInput . selectedStep === id ) { return ; }
377+ private async buildMediaComponent ( stepId : string ) {
378+ if ( ! this . currentCategory || this . currentCategory . content . type !== 'steps' ) {
379+ throw Error ( 'cannot expand step for category of non steps type' + this . currentCategory ?. id ) ;
380+ }
381+ const stepToExpand = assertIsDefined ( this . currentCategory . content . steps . find ( step => step . id === stepId ) ) ;
379382
380383 this . stepDisposables . clear ( ) ;
381384 clearNode ( this . stepMediaComponent ) ;
382385
386+ if ( stepToExpand . media . type === 'image' ) {
387+
388+ this . stepMediaComponent . classList . add ( 'image' ) ;
389+ this . stepMediaComponent . classList . remove ( 'markdown' ) ;
390+
391+ const media = stepToExpand . media ;
392+ const mediaElement = $ < HTMLImageElement > ( 'img' ) ;
393+ this . stepMediaComponent . appendChild ( mediaElement ) ;
394+ mediaElement . setAttribute ( 'alt' , media . altText ) ;
395+ this . updateMediaSourceForColorMode ( mediaElement , media . path ) ;
396+
397+ this . stepDisposables . add ( this . themeService . onDidColorThemeChange ( ( ) => this . updateMediaSourceForColorMode ( mediaElement , media . path ) ) ) ;
398+
399+ } else if ( stepToExpand . media . type === 'markdown' ) {
400+
401+ this . stepMediaComponent . classList . remove ( 'image' ) ;
402+ this . stepMediaComponent . classList . add ( 'markdown' ) ;
403+
404+ const media = stepToExpand . media ;
405+
406+ const webview = this . stepDisposables . add ( this . webviewService . createWebviewElement ( this . webviewID , { } , { localResourceRoots : [ media . root ] } , undefined ) ) ;
407+ webview . mountTo ( this . stepMediaComponent ) ;
408+ webview . html = await this . renderMarkdown ( media . path , media . base ) ;
409+
410+ let isDisposed = false ;
411+ this . stepDisposables . add ( toDisposable ( ( ) => { isDisposed = true ; } ) ) ;
412+
413+ this . stepDisposables . add ( this . themeService . onDidColorThemeChange ( async ( ) => {
414+ // Render again since syntax highlighting of code blocks may have changed
415+ const body = await this . renderMarkdown ( media . path , media . base ) ;
416+ if ( ! isDisposed ) { // Make sure we weren't disposed of in the meantime
417+ webview . html = body ;
418+ }
419+ } ) ) ;
420+ }
421+ }
422+
423+ private async selectStep ( id : string | undefined , delayFocus = true , forceRebuild = false ) {
424+ if ( id && this . editorInput . selectedStep === id && ! forceRebuild ) { return ; }
425+
383426 if ( id ) {
384427 const stepElement = assertIsDefined ( this . container . querySelector < HTMLDivElement > ( `[data-step-id="${ id } "]` ) ) ;
385428 stepElement . parentElement ?. querySelectorAll < HTMLElement > ( '.expanded' ) . forEach ( node => {
@@ -392,49 +435,12 @@ export class GettingStartedPage extends EditorPane {
392435 stepElement . style . height = `` ;
393436 stepElement . style . height = `${ stepElement . scrollHeight } px` ;
394437
395- if ( ! this . currentCategory || this . currentCategory . content . type !== 'steps' ) {
396- throw Error ( 'cannot expand step for category of non steps type' + this . currentCategory ?. id ) ;
397- }
398438 this . editorInput . selectedStep = id ;
399439 this . selectedStepElement = stepElement ;
400- const stepToExpand = assertIsDefined ( this . currentCategory . content . steps . find ( step => step . id === id ) ) ;
401- if ( stepToExpand . media . type === 'image' ) {
402-
403- this . stepMediaComponent . classList . add ( 'image' ) ;
404- this . stepMediaComponent . classList . remove ( 'markdown' ) ;
405-
406- const media = stepToExpand . media ;
407- const mediaElement = $ < HTMLImageElement > ( 'img' ) ;
408- this . stepMediaComponent . appendChild ( mediaElement ) ;
409- mediaElement . setAttribute ( 'alt' , media . altText ) ;
410- this . updateMediaSourceForColorMode ( mediaElement , media . path ) ;
411-
412- this . stepDisposables . add ( this . themeService . onDidColorThemeChange ( ( ) => this . updateMediaSourceForColorMode ( mediaElement , media . path ) ) ) ;
413-
414- } else if ( stepToExpand . media . type === 'markdown' ) {
415440
416- this . stepMediaComponent . classList . remove ( 'image' ) ;
417- this . stepMediaComponent . classList . add ( 'markdown' ) ;
418-
419- const media = stepToExpand . media ;
420-
421- const webview = this . stepDisposables . add ( this . webviewService . createWebviewElement ( this . webviewID , { } , { localResourceRoots : [ media . root ] } , undefined ) ) ;
422- webview . mountTo ( this . stepMediaComponent ) ;
423- webview . html = await this . renderMarkdown ( media . path , media . base ) ;
424-
425- let isDisposed = false ;
426- this . stepDisposables . add ( toDisposable ( ( ) => { isDisposed = true ; } ) ) ;
427-
428- this . stepDisposables . add ( this . themeService . onDidColorThemeChange ( async ( ) => {
429- // Render again since syntax highlighting of code blocks may have changed
430- const body = await this . renderMarkdown ( media . path , media . base ) ;
431- if ( ! isDisposed ) { // Make sure we weren't disposed of in the meantime
432- webview . html = body ;
433- }
434- } ) ) ;
435- }
436441 stepElement . classList . add ( 'expanded' ) ;
437442 stepElement . setAttribute ( 'aria-expanded' , 'true' ) ;
443+ this . buildMediaComponent ( id ) ;
438444 } else {
439445 this . editorInput . selectedStep = undefined ;
440446 }
@@ -951,7 +957,7 @@ export class GettingStartedPage extends EditorPane {
951957 reset ( this . stepsContent , categoryDescriptorComponent , stepListComponent , this . stepMediaComponent ) ;
952958
953959 const toExpand = category . content . steps . find ( step => ! step . done ) ?? category . content . steps [ 0 ] ;
954- this . selectStep ( selectedStep ?? toExpand . id ) ;
960+ this . selectStep ( selectedStep ?? toExpand . id , ! selectedStep , true ) ;
955961
956962 this . detailsScrollbar . scanDomNode ( ) ;
957963 this . detailsPageScrollbar ?. scanDomNode ( ) ;
0 commit comments