File tree Expand file tree Collapse file tree 3 files changed +30
-13
lines changed Expand file tree Collapse file tree 3 files changed +30
-13
lines changed Original file line number Diff line number Diff line change @@ -690,6 +690,10 @@ Blockly.BlockSvg.prototype.duplicateAndDragCallback_ = function() {
690
690
// Using domToBlock instead of domToWorkspace means that the new block
691
691
// will be placed at position (0, 0) in main workspace units.
692
692
var newBlock = Blockly . Xml . domToBlock ( xml , ws ) ;
693
+
694
+ // Scratch-specific: Give shadow dom new IDs to prevent duplicating on paste
695
+ Blockly . utils . changeObscuredShadowIds ( newBlock ) ;
696
+
693
697
var svgRootNew = newBlock . getSvgRoot ( ) ;
694
698
if ( ! svgRootNew ) {
695
699
throw new Error ( 'newBlock is not rendered.' ) ;
Original file line number Diff line number Diff line change @@ -931,3 +931,26 @@ Blockly.utils.setCssTransform = function(node, transform) {
931
931
node . style [ 'transform' ] = transform ;
932
932
node . style [ '-webkit-transform' ] = transform ;
933
933
} ;
934
+
935
+
936
+ /**
937
+ * Re-assign obscured shadow blocks new IDs to prevent collisions
938
+ * Scratch specific to help the VM handle deleting obscured shadows.
939
+ * @param {Blockly.Block } block the root block to be processed.
940
+ */
941
+ Blockly . utils . changeObscuredShadowIds = function ( block ) {
942
+ var blocks = block . getDescendants ( ) ;
943
+ for ( var i = blocks . length - 1 ; i >= 0 ; i -- ) {
944
+ var descendant = blocks [ i ] ;
945
+ for ( var j = 0 ; j < descendant . inputList . length ; j ++ ) {
946
+ var connection = descendant . inputList [ j ] . connection ;
947
+ if ( connection ) {
948
+ var shadowDom = connection . getShadowDom ( ) ;
949
+ if ( shadowDom ) {
950
+ shadowDom . setAttribute ( 'id' , Blockly . utils . genUid ( ) ) ;
951
+ connection . setShadowDom ( shadowDom ) ;
952
+ }
953
+ }
954
+ }
955
+ }
956
+ } ;
Original file line number Diff line number Diff line change @@ -945,22 +945,12 @@ Blockly.WorkspaceSvg.prototype.paste = function(xmlBlock) {
945
945
try {
946
946
var block = Blockly . Xml . domToBlock ( xmlBlock , this ) ;
947
947
948
+ // Scratch-specific: Give shadow dom new IDs to prevent duplicating on paste
949
+ Blockly . utils . changeObscuredShadowIds ( block ) ;
950
+
948
951
var blocks = block . getDescendants ( ) ;
949
952
for ( var i = blocks . length - 1 ; i >= 0 ; i -- ) {
950
953
var descendant = blocks [ i ] ;
951
-
952
- // Scratch-specific: Give shadow dom new IDs to prevent duplicating on paste
953
- for ( var j = 0 ; j < descendant . inputList . length ; j ++ ) {
954
- var connection = descendant . inputList [ j ] . connection ;
955
- if ( connection ) {
956
- var shadowDom = connection . getShadowDom ( ) ;
957
- if ( shadowDom ) {
958
- shadowDom . setAttribute ( 'id' , Blockly . utils . genUid ( ) ) ;
959
- connection . setShadowDom ( shadowDom ) ;
960
- }
961
- }
962
- }
963
-
964
954
// Rerender to get around problem with IE and Edge not measuring text
965
955
// correctly when it is hidden.
966
956
if ( goog . userAgent . IE || goog . userAgent . EDGE ) {
You can’t perform that action at this time.
0 commit comments