@@ -438,7 +438,8 @@ class Blocks {
438438 oldInput : e . oldInputName ,
439439 newParent : e . newParentId ,
440440 newInput : e . newInputName ,
441- newCoordinate : e . newCoordinate
441+ newCoordinate : e . newCoordinate ,
442+ fromExpandable : e . isFromExpandable ,
442443 } ) ;
443444 break ;
444445 case 'dragOutside' :
@@ -477,7 +478,7 @@ class Blocks {
477478 }
478479 } , 100 ) ;
479480 }
480- this . deleteBlock ( e . blockId , false , e . isFromExpandable || block . opcode . startsWith ( "argument_reporter_" ) ) ;
481+ this . deleteBlock ( e . blockId , false ) ;
481482 break ;
482483 case 'var_create' :
483484 this . resetCache ( ) ; // tw: more aggressive cache resetting
@@ -835,11 +836,17 @@ class Blocks {
835836 }
836837
837838 const block = this . _blocks [ e . id ] ;
839+
838840 // Track whether a change actually occurred
839841 // ignoring changes like routine re-positioning
840842 // of a block when loading a workspace
841843 let didChange = false ;
842844
845+ // Determine wether we should remove an input
846+ // from the parent block. Typically remove an
847+ // expandable or procedure update
848+ const shouldRemoveInput = e . fromExpandable || block . opcode . startsWith ( "argument_reporter_" ) ;
849+
843850 // Move coordinate changes.
844851 if ( e . newCoordinate ) {
845852
@@ -855,7 +862,8 @@ class Blocks {
855862 if ( typeof e . oldInput !== 'undefined' &&
856863 oldParent . inputs [ e . oldInput ] . block === e . id ) {
857864 // This block was connected to the old parent's input.
858- oldParent . inputs [ e . oldInput ] . block = null ;
865+ if ( shouldRemoveInput ) delete oldParent . inputs [ e . oldInput ] ;
866+ else oldParent . inputs [ e . oldInput ] . block = null ;
859867 } else if ( oldParent . next === e . id ) {
860868 // This block was connected to the old parent's next connection.
861869 oldParent . next = null ;
@@ -931,10 +939,8 @@ class Blocks {
931939 * with the given ID does not exist.
932940 * @param {!string } blockId Id of block to delete
933941 * @param {boolean } preserveStack If we should reconect the bottom blocks to the top block
934- * @param {boolean } isSpecialShadow If we should remove the input that contains this block,
935- * typically called for procedures and expandables
936942 */
937- deleteBlock ( blockId , preserveStack , isSpecialShadow ) {
943+ deleteBlock ( blockId , preserveStack ) {
938944 // Get block
939945 const block = this . _blocks [ blockId ] ;
940946 if ( ! block ) {
@@ -988,17 +994,6 @@ class Blocks {
988994 this . _scripts . splice ( i , 1 ) ;
989995 }
990996
991- if ( isSpecialShadow && block . parent !== null ) {
992- const parent = this . _blocks [ block . parent ] ;
993-
994- for ( const inputName in parent . inputs ) {
995- if ( parent . inputs [ inputName ] . block === blockId ) {
996- delete parent . inputs [ inputName ] ;
997- break ;
998- }
999- }
1000- }
1001-
1002997 // Delete block itself.
1003998 delete this . _blocks [ blockId ] ;
1004999
0 commit comments