Mark fields as dirty when the workspace becomes visible. (#3072)

* Mark fields as dirty when the workspace becomes visible.
This commit is contained in:
Sam El-Husseini
2019-09-23 11:21:45 -07:00
committed by GitHub
parent 593383e18a
commit 494487b37f
4 changed files with 37 additions and 0 deletions

View File

@@ -540,6 +540,16 @@ Blockly.BlockSvg.prototype.getBoundingRectangle = function() {
return new Blockly.utils.Rect(top, bottom, left, right);
};
/**
* Notify every input on this block to mark its fields as dirty.
* A dirty field is a field that needs to be re-rendererd.
*/
Blockly.BlockSvg.prototype.markDirty = function() {
for (var i = 0, input; input = this.inputList[i]; i++) {
input.markDirty();
}
};
/**
* Set whether the block is collapsed or not.
* @param {boolean} collapsed True if collapsed.

View File

@@ -688,6 +688,17 @@ Blockly.Field.prototype.setText = function(_newText) {
throw Error('setText method is deprecated');
};
/**
* Force a rerender of the block that this field is installed on, which will
* rerender this field and adjust for any sizing changes.
* Other fields on the same block will not rerender, because their sizes have
* already been recorded.
* @package
*/
Blockly.Field.prototype.markDirty = function() {
this.isDirty_ = true;
};
/**
* Force a rerender of the block that this field is installed on, which will
* rerender this field and adjust for any sizing changes.

View File

@@ -206,6 +206,16 @@ Blockly.Input.prototype.setVisible = function(visible) {
return renderList;
};
/**
* Mark all fields on this input as dirty.
* @package
*/
Blockly.Input.prototype.markDirty = function() {
for (var y = 0, field; field = this.fieldRow[y]; y++) {
field.markDirty();
}
};
/**
* Change a connection's compatibility.
* @param {string|Array.<string>|null} check Compatible value type or

View File

@@ -1079,6 +1079,12 @@ Blockly.WorkspaceSvg.prototype.setVisible = function(isVisible) {
this.toolbox_.HtmlDiv.style.display = isVisible ? 'block' : 'none';
}
if (isVisible) {
var blocks = this.getAllBlocks(false);
// Tell each block on the workspace to mark its fields as dirty.
for (var i = blocks.length - 1; i >= 0; i--) {
blocks[i].markDirty();
}
this.render();
if (this.toolbox_) {
this.toolbox_.position();