@@ -886,23 +886,32 @@ class Blocks {
886
886
typeof e . oldInput !== "undefined" &&
887
887
oldParent . inputs [ e . oldInput ] . block === e . id
888
888
) {
889
- // This block was connected to the old parent's input. We either
890
- // want to restore the shadow block that previously occupied
891
- // this input, or set it to null (which `.shadow` will be if
892
- // there was no shadow previously)
893
- oldParent . inputs [ e . oldInput ] . block =
894
- oldParent . inputs [ e . oldInput ] . shadow ;
889
+ // This block was connected to an input. We either want to
890
+ // restore the shadow block that previously occupied
891
+ // this input, or null out the input's block.
892
+ const shadow = oldParent . inputs [ e . oldInput ] . shadow ;
893
+ if ( shadow && e . id !== shadow ) {
894
+ oldParent . inputs [ e . oldInput ] . block = shadow ;
895
+ this . _blocks [ shadow ] . parent = oldParent . id ;
896
+ } else {
897
+ oldParent . inputs [ e . oldInput ] . block = null ;
898
+ if ( e . id !== shadow ) {
899
+ this . _blocks [ e . id ] . parent = null ;
900
+ }
901
+ }
895
902
} else if ( oldParent . next === e . id ) {
896
903
// This block was connected to the old parent's next connection.
897
904
oldParent . next = null ;
905
+ this . _blocks [ e . id ] . parent = null ;
898
906
}
899
- this . _blocks [ e . id ] . parent = null ;
900
907
didChange = true ;
901
908
}
902
909
903
910
// Is this block a top-level block?
904
911
if ( typeof e . newParent === "undefined" ) {
905
- this . _addScript ( e . id ) ;
912
+ if ( ! this . _blocks [ e . id ] . shadow ) {
913
+ this . _addScript ( e . id ) ;
914
+ }
906
915
} else {
907
916
// Remove script, if one exists.
908
917
this . _deleteScript ( e . id ) ;
0 commit comments