Fix setValue not handling block disposal (#3766)

This commit is contained in:
Beka Westberg
2020-04-06 09:59:30 -07:00
committed by GitHub
parent b64028521f
commit bcfde92afb
3 changed files with 26 additions and 3 deletions

View File

@@ -858,16 +858,20 @@ Blockly.Field.prototype.setValue = function(newValue) {
return;
}
}
var source = this.sourceBlock_;
if (source && source.disposed) {
doLogging && console.log('source disposed, return');
return;
}
var oldValue = this.getValue();
if (oldValue === newValue) {
doLogging && console.log('same, return');
// No change.
return;
}
if (this.sourceBlock_ && Blockly.Events.isEnabled()) {
if (source && Blockly.Events.isEnabled()) {
Blockly.Events.fire(new Blockly.Events.BlockChange(
this.sourceBlock_, 'field', this.name || null, oldValue, newValue));
source, 'field', this.name || null, oldValue, newValue));
}
this.doValueUpdate_(newValue);
if (this.isDirty_) {

View File

@@ -1343,6 +1343,22 @@ Blockly.Blocks['test_images_clickhandler'] = {
}
};
Blockly.Blocks['test_validators_dispose_block'] = {
init: function() {
this.appendDummyInput()
.appendField("dispose block")
.appendField(new Blockly.FieldTextInput("default", this.validate), "INPUT");
this.setColour(230);
this.setCommentText('Any changes to the text cause the block to be disposed');
},
validate: function(newValue) {
if (newValue != "default") {
this.getSourceBlock().dispose(true);
}
}
};
Blockly.Blocks['test_validators_text_null'] = {
init: function() {
this.appendDummyInput()

View File

@@ -1677,6 +1677,9 @@ var spaghettiXml = [
<button text="add blocks to workspace" callbackKey="addAllBlocksToWorkspace"></button>
<sep gap="8"></sep>
<button text="set input" callbackKey="setInput"></button>
<label text="Dispose block"></label>
<sep gap="12"></sep>
<block type="test_validators_dispose_block"></block>
<label text="Angles"></label>
<sep gap="12"></sep>
<block type="test_validators_angle_null"></block>