mirror of
https://github.com/scratchfoundation/scratch-blocks.git
synced 2025-08-02 01:02:12 -04:00
Avoid IE and Edge re-rendering (#1326)
* Fix wrong width of field_dropdown with an image on Edge / IE * Avoid re-rendering on IE and Edge by using getBBox().width to compute the text width on those browsers
This commit is contained in:
parent
c2e7f6dfe8
commit
c55824d619
4 changed files with 7 additions and 40 deletions
|
@ -448,10 +448,13 @@ Blockly.Field.getCachedWidth = function(textElement) {
|
|||
|
||||
// Attempt to compute fetch the width of the SVG text element.
|
||||
try {
|
||||
width = textElement.getComputedTextLength();
|
||||
if (goog.userAgent.IE || goog.userAgent.EDGE) {
|
||||
width = textElement.getBBox().width;
|
||||
} else {
|
||||
width = textElement.getComputedTextLength();
|
||||
}
|
||||
} catch (e) {
|
||||
// MSIE 11 and Edge are known to throw "Unexpected call to method or
|
||||
// property access." if the block is hidden. Instead, use an
|
||||
// In other cases where we fail to geth the computed text. Instead, use an
|
||||
// approximation and do not cache the result. At some later point in time
|
||||
// when the block is inserted into the visible DOM, this method will be
|
||||
// called again and, at that point in time, will not throw an exception.
|
||||
|
|
|
@ -697,14 +697,6 @@ Blockly.Flyout.prototype.createBlock = function(originalBlock) {
|
|||
this.targetWorkspace_.setResizesEnabled(false);
|
||||
try {
|
||||
newBlock = this.placeNewBlock_(originalBlock);
|
||||
//Force a render on IE and Edge to get around the issue described in
|
||||
//Blockly.Field.getCachedWidth
|
||||
if (goog.userAgent.IE || goog.userAgent.EDGE) {
|
||||
var blocks = newBlock.getDescendants();
|
||||
for (var i = blocks.length - 1; i >= 0; i--) {
|
||||
blocks[i].render(false);
|
||||
}
|
||||
}
|
||||
// Close the flyout.
|
||||
Blockly.hideChaff();
|
||||
} finally {
|
||||
|
|
|
@ -953,21 +953,8 @@ Blockly.WorkspaceSvg.prototype.paste = function(xmlBlock) {
|
|||
Blockly.Events.disable();
|
||||
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];
|
||||
// Rerender to get around problem with IE and Edge not measuring text
|
||||
// correctly when it is hidden.
|
||||
if (goog.userAgent.IE || goog.userAgent.EDGE) {
|
||||
descendant.render(false);
|
||||
}
|
||||
}
|
||||
|
||||
// Move the duplicate to original position.
|
||||
Blockly.utils.changeObscuredShadowIds(block); // Move the duplicate to original position.
|
||||
var blockX = parseInt(xmlBlock.getAttribute('x'), 10);
|
||||
var blockY = parseInt(xmlBlock.getAttribute('y'), 10);
|
||||
if (!isNaN(blockX) && !isNaN(blockY)) {
|
||||
|
|
15
core/xml.js
15
core/xml.js
|
@ -473,21 +473,6 @@ Blockly.Xml.domToBlock = function(xmlBlock, workspace) {
|
|||
setTimeout(function() {
|
||||
if (topBlock.workspace) { // Check that the block hasn't been deleted.
|
||||
topBlock.setConnectionsHidden(false);
|
||||
// Force a render on IE and Edge to get around the issue described in
|
||||
// Blockly.Field.getCachedWidth
|
||||
if (goog.userAgent.IE || goog.userAgent.EDGE) {
|
||||
topBlock.render();
|
||||
}
|
||||
}
|
||||
}, 1);
|
||||
} else {
|
||||
setTimeout(function() {
|
||||
if (topBlock.workspace) { // Check that the block hasn't been deleted.
|
||||
// Force a render on IE and Edge to get around the issue described in
|
||||
// Blockly.Field.getCachedWidth
|
||||
if (goog.userAgent.IE || goog.userAgent.EDGE) {
|
||||
topBlock.render();
|
||||
}
|
||||
}
|
||||
}, 1);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue