mirror of
https://github.com/google/blockly.git
synced 2026-01-07 00:50:27 +01:00
Fix setValue not handling block disposal (#3766)
This commit is contained in:
@@ -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_) {
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user