diff --git a/core/block.js b/core/block.js index 5addb931e..c0ab22d49 100644 --- a/core/block.js +++ b/core/block.js @@ -174,6 +174,9 @@ Blockly.Block = function(workspace, prototypeName, opt_id) { */ this.hat = undefined; + /** @type {?boolean} */ + this.rendered = null; + /** * A count of statement inputs on the block. * @type {number} diff --git a/core/field_dropdown.js b/core/field_dropdown.js index f55911101..4874964da 100644 --- a/core/field_dropdown.js +++ b/core/field_dropdown.js @@ -67,6 +67,20 @@ Blockly.FieldDropdown = function(menuGenerator, opt_validator, opt_config) { */ this.generatedOptions_ = null; + /** + * The prefix field label, of common words set after options are trimmed. + * @type {?string} + * @package + */ + this.prefixField = null; + + /** + * The suffix field label, of common words set after options are trimmed. + * @type {?string} + * @package + */ + this.suffixField = null; + this.trimOptions_(); /** @@ -373,8 +387,6 @@ Blockly.FieldDropdown.prototype.onItemSelected_ = function(menu, menuItem) { * @private */ Blockly.FieldDropdown.prototype.trimOptions_ = function() { - this.prefixField = null; - this.suffixField = null; var options = this.menuGenerator_; if (!Array.isArray(options)) { return; diff --git a/core/input.js b/core/input.js index dd56adf6a..392ee1550 100644 --- a/core/input.js +++ b/core/input.js @@ -109,19 +109,21 @@ Blockly.Input.prototype.insertFieldAt = function(index, field, opt_name) { field.name = opt_name; field.setVisible(this.isVisible()); - if (field.prefixField) { + var fieldDropdown = /** @type {Blockly.FieldDropdown} */ (field); + if (fieldDropdown.prefixField) { // Add any prefix. - index = this.insertFieldAt(index, field.prefixField); + index = this.insertFieldAt(index, fieldDropdown.prefixField); } // Add the field to the field row. this.fieldRow.splice(index, 0, field); ++index; - if (field.suffixField) { + if (fieldDropdown.suffixField) { // Add any suffix. - index = this.insertFieldAt(index, field.suffixField); + index = this.insertFieldAt(index, fieldDropdown.suffixField); } if (this.sourceBlock_.rendered) { + this.sourceBlock_ = /** @type {!Blockly.BlockSvg} */ (this.sourceBlock_); this.sourceBlock_.render(); // Adding a field will cause the block to change shape. this.sourceBlock_.bumpNeighbours(); @@ -140,6 +142,7 @@ Blockly.Input.prototype.removeField = function(name) { field.dispose(); this.fieldRow.splice(i, 1); if (this.sourceBlock_.rendered) { + this.sourceBlock_ = /** @type {!Blockly.BlockSvg} */ (this.sourceBlock_); this.sourceBlock_.render(); // Removing a field will cause the block to change shape. this.sourceBlock_.bumpNeighbours(); @@ -162,7 +165,7 @@ Blockly.Input.prototype.isVisible = function() { * Sets whether this input is visible or not. * Should only be used to collapse/uncollapse a block. * @param {boolean} visible True if visible. - * @return {!Array.} List of blocks to render. + * @return {!Array.} List of blocks to render. * @package */ Blockly.Input.prototype.setVisible = function(visible) { @@ -179,6 +182,8 @@ Blockly.Input.prototype.setVisible = function(visible) { field.setVisible(visible); } if (this.connection) { + this.connection = + /** @type {!Blockly.RenderedConnection} */ (this.connection); // Has a connection. if (visible) { renderList = this.connection.startTrackingAll(); @@ -226,6 +231,7 @@ Blockly.Input.prototype.setCheck = function(check) { Blockly.Input.prototype.setAlign = function(align) { this.align = align; if (this.sourceBlock_.rendered) { + this.sourceBlock_ = /** @type {!Blockly.BlockSvg} */ (this.sourceBlock_); this.sourceBlock_.render(); } return this;