mirror of
https://github.com/scratchfoundation/scratch-blocks.git
synced 2025-07-23 20:29:32 -04:00
Merge pull request #1028 from paulkaplan/fix-duplicate-on-duplicate
Add shadow dom ID uniquifier to 'Duplicate' code path
This commit is contained in:
commit
ddb623455f
3 changed files with 30 additions and 13 deletions
|
@ -690,6 +690,10 @@ Blockly.BlockSvg.prototype.duplicateAndDragCallback_ = function() {
|
|||
// Using domToBlock instead of domToWorkspace means that the new block
|
||||
// will be placed at position (0, 0) in main workspace units.
|
||||
var newBlock = Blockly.Xml.domToBlock(xml, ws);
|
||||
|
||||
// Scratch-specific: Give shadow dom new IDs to prevent duplicating on paste
|
||||
Blockly.utils.changeObscuredShadowIds(newBlock);
|
||||
|
||||
var svgRootNew = newBlock.getSvgRoot();
|
||||
if (!svgRootNew) {
|
||||
throw new Error('newBlock is not rendered.');
|
||||
|
|
|
@ -931,3 +931,26 @@ Blockly.utils.setCssTransform = function(node, transform) {
|
|||
node.style['transform'] = transform;
|
||||
node.style['-webkit-transform'] = transform;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Re-assign obscured shadow blocks new IDs to prevent collisions
|
||||
* Scratch specific to help the VM handle deleting obscured shadows.
|
||||
* @param {Blockly.Block} block the root block to be processed.
|
||||
*/
|
||||
Blockly.utils.changeObscuredShadowIds = function(block) {
|
||||
var blocks = block.getDescendants();
|
||||
for (var i = blocks.length - 1; i >= 0; i--) {
|
||||
var descendant = blocks[i];
|
||||
for (var j = 0; j < descendant.inputList.length; j++) {
|
||||
var connection = descendant.inputList[j].connection;
|
||||
if (connection) {
|
||||
var shadowDom = connection.getShadowDom();
|
||||
if (shadowDom) {
|
||||
shadowDom.setAttribute('id', Blockly.utils.genUid());
|
||||
connection.setShadowDom(shadowDom);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
@ -945,22 +945,12 @@ Blockly.WorkspaceSvg.prototype.paste = function(xmlBlock) {
|
|||
try {
|
||||
var block = Blockly.Xml.domToBlock(xmlBlock, this);
|
||||
|
||||
// Scratch-specific: Give shadow dom new IDs to prevent duplicating on paste
|
||||
Blockly.utils.changeObscuredShadowIds(block);
|
||||
|
||||
var blocks = block.getDescendants();
|
||||
for (var i = blocks.length - 1; i >= 0; i--) {
|
||||
var descendant = blocks[i];
|
||||
|
||||
// Scratch-specific: Give shadow dom new IDs to prevent duplicating on paste
|
||||
for (var j = 0; j < descendant.inputList.length; j++) {
|
||||
var connection = descendant.inputList[j].connection;
|
||||
if (connection) {
|
||||
var shadowDom = connection.getShadowDom();
|
||||
if (shadowDom) {
|
||||
shadowDom.setAttribute('id', Blockly.utils.genUid());
|
||||
connection.setShadowDom(shadowDom);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Rerender to get around problem with IE and Edge not measuring text
|
||||
// correctly when it is hidden.
|
||||
if (goog.userAgent.IE || goog.userAgent.EDGE) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue