@@ -264,7 +264,7 @@ Blockly.Blocks['control_expandableIf'] = {
264264 const prevText = this . getInput ( `TEXTSTART${ this . branches_ } ` ) ;
265265 if ( prevText ) prevText . appendField ( "if" ) ;
266266 else this . appendDummyInput ( `TEXTSTART${ this . branches_ } ` ) . appendField ( "if" ) ;
267- const input = this . appendValueInput ( `BOOL${ this . branches_ } ` ) ;
267+ const input = this . appendValueInput ( `BOOL${ this . branches_ } ` ) . setCheck ( "Boolean" ) ;
268268 if ( shouldPopulate ) this . fillInBlock ( input . connection , "checkbox" ) ;
269269 this . appendDummyInput ( `TEXTEND${ this . branches_ } ` ) . appendField ( "then" ) ;
270270
@@ -294,6 +294,23 @@ Blockly.Blocks['control_expandableIf'] = {
294294 // on load
295295 const inputCount = Number ( xmlElement . getAttribute ( "branches" ) ) ;
296296 let branchCount = isNaN ( inputCount ) ? 0 : inputCount ;
297+ let needsActionConnect = false , oldConnections ;
298+
299+ if ( this . inputList . length - 1 > 0 ) {
300+ // this was a control z action
301+ needsActionConnect = true ;
302+ oldConnections = this . getConnections_ ( ) . map ( c => c . targetBlock ( ) ) ;
303+
304+ // clear block
305+ for ( var i = this . inputList . length - 1 ; i -- ; ) {
306+ const input = this . inputList [ i ] ;
307+ if ( input . name . startsWith ( "SUBSTACK" ) || input . name . startsWith ( "BOOL" ) ) {
308+ if ( input . connection . targetBlock ( ) ) input . connection . disconnect ( ) ;
309+ }
310+ this . removeInput ( input . name ) ;
311+ }
312+ }
313+
297314 if ( branchCount > 1 ) {
298315 branchCount = ( branchCount * 2 ) - 1 ;
299316 if ( xmlElement . getAttribute ( "ends-in-else" ) === "true" ) branchCount -= 1 ;
@@ -310,6 +327,25 @@ Blockly.Blocks['control_expandableIf'] = {
310327 }
311328
312329 this . fixupButtons ( ) ;
330+ if ( needsActionConnect ) {
331+ let index = 2 ;
332+ for ( var i = 0 ; i < this . inputList . length ; i ++ ) {
333+ const input = this . inputList [ i ] ;
334+ if ( input . name . startsWith ( "SUBSTACK" ) || input . name . startsWith ( "BOOL" ) ) {
335+ const oldBlock = oldConnections [ index ] ;
336+ if ( oldBlock ) {
337+ try {
338+ const connector = oldBlock . outputConnection ?? oldBlock . previousConnection ;
339+ input . connection . connect ( connector ) ;
340+ } catch { }
341+ }
342+ index ++ ;
343+ }
344+ }
345+ for ( var i = index - 1 ; i < oldConnections . length ; i ++ ) {
346+ if ( oldConnections [ i ] ?. type === "checkbox" ) oldConnections [ i ] . dispose ( ) ;
347+ }
348+ }
313349 } ,
314350
315351 onExpandableButtonClicked_ : function ( isAdding ) {
0 commit comments