@@ -501,22 +501,32 @@ export class Block {
501501 // Detach this block from the parent's tree.
502502 this . previousConnection . disconnect ( ) ;
503503 }
504- const nextBlock = this . getNextBlock ( ) ;
505- if ( opt_healStack && nextBlock && ! nextBlock . isShadow ( ) ) {
506- // Disconnect the next statement.
507- const nextTarget = this . nextConnection ?. targetConnection ?? null ;
508- nextTarget ?. disconnect ( ) ;
509- if (
510- previousTarget &&
511- this . workspace . connectionChecker . canConnect (
512- previousTarget ,
513- nextTarget ,
514- false ,
515- )
516- ) {
517- // Attach the next statement to the previous statement.
518- previousTarget . connect ( nextTarget ! ) ;
519- }
504+
505+ if ( ! opt_healStack ) return ;
506+
507+ // Immovable or shadow next blocks need to move along with the block; keep
508+ // going until we encounter a normal block or run off the end of the stack.
509+ let nextBlock = this . getNextBlock ( ) ;
510+ while ( nextBlock && ( nextBlock . isShadow ( ) || ! nextBlock . isMovable ( ) ) ) {
511+ nextBlock = nextBlock . getNextBlock ( ) ;
512+ }
513+ if ( ! nextBlock ) return ;
514+
515+ // Disconnect the next statement.
516+ const nextTarget =
517+ nextBlock . previousConnection ?. targetBlock ( ) ?. nextConnection
518+ ?. targetConnection ?? null ;
519+ nextTarget ?. disconnect ( ) ;
520+ if (
521+ previousTarget &&
522+ this . workspace . connectionChecker . canConnect (
523+ previousTarget ,
524+ nextTarget ,
525+ false ,
526+ )
527+ ) {
528+ // Attach the next statement to the previous statement.
529+ previousTarget . connect ( nextTarget ! ) ;
520530 }
521531 }
522532
@@ -1116,7 +1126,7 @@ export class Block {
11161126 /**
11171127 * Returns a generator that provides every field on the block.
11181128 *
1119- * @yields A generator that can be used to iterate the fields on the block.
1129+ * @returns A generator that can be used to iterate the fields on the block.
11201130 */
11211131 * getFields ( ) : Generator < Field , undefined , void > {
11221132 for ( const input of this . inputList ) {
0 commit comments