mirror of
https://github.com/google/blockly.git
synced 2026-01-09 10:00:09 +01: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:
committed by
Rachel Fenichel
parent
cc8a12a574
commit
9c0de1ae8d
@@ -339,12 +339,6 @@ Blockly.BlockSvg.prototype.renderFields_ =
|
||||
continue;
|
||||
}
|
||||
|
||||
// Force a width re-calculation on IE and Edge to get around the issue
|
||||
// described in Blockly.Field.getCachedWidth
|
||||
if (goog.userAgent.IE || goog.userAgent.EDGE) {
|
||||
field.updateWidth();
|
||||
}
|
||||
|
||||
if (this.RTL) {
|
||||
cursorX -= field.renderSep + field.renderWidth;
|
||||
root.setAttribute('transform',
|
||||
|
||||
@@ -351,10 +351,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.
|
||||
|
||||
@@ -607,14 +607,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 {
|
||||
|
||||
@@ -857,14 +857,6 @@ Blockly.WorkspaceSvg.prototype.paste = function(xmlBlock) {
|
||||
Blockly.Events.disable();
|
||||
try {
|
||||
var block = Blockly.Xml.domToBlock(xmlBlock, this);
|
||||
// Rerender to get around problem with IE and Edge not measuring text
|
||||
// correctly when it is hidden.
|
||||
if (goog.userAgent.IE || goog.userAgent.EDGE) {
|
||||
var blocks = block.getDescendants();
|
||||
for (var i = blocks.length - 1; i >= 0; i--) {
|
||||
blocks[i].render(false);
|
||||
}
|
||||
}
|
||||
// Move the duplicate to original position.
|
||||
var blockX = parseInt(xmlBlock.getAttribute('x'), 10);
|
||||
var blockY = parseInt(xmlBlock.getAttribute('y'), 10);
|
||||
|
||||
Reference in New Issue
Block a user