@@ -1200,8 +1200,6 @@ export class Editor extends toolboxeditor.ToolboxEditor {
12001200 * ensuring all provided ids are valid and setting up the corresponding target queries.
12011201 */
12021202 private createTourFromResponse = ( response : ErrorHelpTourResponse ) : pxt . tour . TourConfig => {
1203- const validBlockIds = this . parent . getBlocks ( ) . map ( ( b ) => b . id ) ;
1204-
12051203 const tourSteps : pxt . tour . BubbleStep [ ] = [ ] ;
12061204 let invalidBlockIdCount = 0 ;
12071205 for ( const step of response . explanationSteps ) {
@@ -1213,10 +1211,24 @@ export class Editor extends toolboxeditor.ToolboxEditor {
12131211 } as pxt . tour . BubbleStep ;
12141212
12151213 if ( step . elementId ) {
1216- if ( validBlockIds . includes ( step . elementId ) ) {
1214+ const targetBlock = this . editor ?. getBlockById ( step . elementId ) ;
1215+ if ( targetBlock ) {
1216+ const targetBlockRoot = targetBlock . getRootBlock ( ) ;
1217+ const isInsideCollapsedBlock = targetBlockRoot . isCollapsed ( ) && targetBlockRoot . id !== step . elementId ;
12171218 tourStep . targetQuery = `g[data-id="${ step . elementId } "]:not(.blocklyFlyout g)` ;
12181219 tourStep . location = pxt . tour . BubbleLocation . Right ;
1219- tourStep . onStepBegin = ( ) => this . editor . centerOnBlock ( step . elementId , true ) ;
1220+
1221+ tourStep . onStepBegin = ( ) => {
1222+ if ( isInsideCollapsedBlock ) {
1223+ targetBlockRoot . setCollapsed ( false ) ;
1224+ targetBlockRoot . bringToFront ( ) ;
1225+ targetBlockRoot . render ( ) ;
1226+ }
1227+ this . editor . centerOnBlock ( step . elementId , true ) ;
1228+ } ;
1229+ if ( isInsideCollapsedBlock ) {
1230+ tourStep . onStepEnd = ( ) => targetBlockRoot . setCollapsed ( true ) ;
1231+ }
12201232 } else {
12211233 // Do not add the tour target, but keep the step in case it's still helpful.
12221234 pxt . tickEvent ( "errorHelp.invalidBlockId" ) ;
@@ -1239,6 +1251,15 @@ export class Editor extends toolboxeditor.ToolboxEditor {
12391251 } ;
12401252 }
12411253
1254+ private getVisibleBlockAncestorId ( blockId : string ) : string | undefined {
1255+ const block = this . editor ?. getBlockById ( blockId ) as Blockly . BlockSvg ;
1256+ const rootBlock = block ?. getRootBlock ( ) as Blockly . BlockSvg ;
1257+ if ( ! block || ! rootBlock ) {
1258+ return undefined ;
1259+ }
1260+ return rootBlock . isCollapsed ( ) ? rootBlock . id : blockId ;
1261+ }
1262+
12421263 private handleErrorHelpFeedback ( positive : boolean , responseData : any ) {
12431264 pxt . tickEvent ( "errorHelp.feedback" , { ...responseData , positive : positive + "" } ) ;
12441265 }
0 commit comments