Added getSourceBlock function to field. (#2508)

This commit is contained in:
Beka Westberg
2019-05-29 12:50:00 -07:00
committed by RoboErikG
parent 9099ee8c14
commit 73ff710a4d
8 changed files with 26 additions and 19 deletions

View File

@@ -250,7 +250,7 @@ Blockly.DropDownDiv.showPositionedByField = function(owner,
// Set bounds to workspace; show the drop-down.
Blockly.DropDownDiv.positionToField_ = true;
Blockly.DropDownDiv.setBoundsElement(
owner.sourceBlock_.workspace.getParentSvg().parentNode);
owner.getSourceBlock().workspace.getParentSvg().parentNode);
return Blockly.DropDownDiv.show(
owner, primaryX, primaryY, secondaryX, secondaryY, opt_onHide);
};
@@ -514,7 +514,7 @@ Blockly.DropDownDiv.repositionForWindowResize = function() {
// when a field is focused, the soft keyboard opens triggering a window resize
// event and we want the dropdown div to stick around so users can type into it.
if (Blockly.DropDownDiv.owner_) {
var block = Blockly.DropDownDiv.owner_.sourceBlock_;
var block = Blockly.DropDownDiv.owner_.getSourceBlock();
var scale = block.workspace.scale;
var bBox = {
width: Blockly.DropDownDiv.positionToField_ ?

View File

@@ -211,6 +211,14 @@ Blockly.Field.prototype.setSourceBlock = function(block) {
this.sourceBlock_ = block;
};
/**
* Get the block this field is attached to.
* @return {Blockly.Block} The block containing this field.
*/
Blockly.Field.prototype.getSourceBlock = function() {
return this.sourceBlock_;
};
/**
* Initialize everything to render this field. Override
* methods initModel and initView rather than this method.

View File

@@ -163,11 +163,11 @@ Blockly.Procedures.rename = function(name) {
name = name.replace(/^[\s\xa0]+|[\s\xa0]+$/g, '');
// Ensure two identically-named procedures don't exist.
var legalName = Blockly.Procedures.findLegalName(name, this.sourceBlock_);
var legalName = Blockly.Procedures.findLegalName(name, this.getSourceBlock());
var oldName = this.text_;
if (oldName != name && oldName != legalName) {
// Rename any callers.
var blocks = this.sourceBlock_.workspace.getAllBlocks(false);
var blocks = this.getSourceBlock().workspace.getAllBlocks(false);
for (var i = 0; i < blocks.length; i++) {
if (blocks[i].renameProcedure) {
blocks[i].renameProcedure(oldName, legalName);