Properly set the display style on blocks when connections are unhidden

We weren't always setting the display style on blocks when the hidden
state changed on a connection. This meant that sometimes unhiding a
connection would cause the attached block to be invisible.

This moves the display style code into the setHidden so it is never
skipped.
This commit is contained in:
Erik Pasternak
2019-07-18 14:08:53 -07:00
committed by Rachel Fenichel
parent ea4c3c59d5
commit c95d5771c8

View File

@@ -283,6 +283,12 @@ Blockly.RenderedConnection.prototype.setHidden = function(hidden) {
} else if (!hidden && !this.inDB_) {
this.db_.addConnection(this);
}
if (this.isSuperior() && this.targetBlock()) {
var display = hidden ? 'none' : 'block';
var renderedBlock = this.targetBlock();
renderedBlock.getSvgRoot().style.display = display;
renderedBlock.rendered = !hidden;
}
};
/**
@@ -344,11 +350,6 @@ Blockly.RenderedConnection.prototype.connect = function(otherConnection) {
} else {
superiorConnection.unhideAll();
}
var renderedBlock = superiorConnection.targetBlock();
var display = superiorConnection.hidden_ ? 'none' : 'block';
renderedBlock.getSvgRoot().style.display = display;
renderedBlock.rendered = !superiorConnection.hidden_;
}
};
@@ -358,17 +359,17 @@ Blockly.RenderedConnection.prototype.connect = function(otherConnection) {
*/
Blockly.RenderedConnection.prototype.disconnect = function() {
var superiorConnection = this.isSuperior() ? this : this.targetConnection;
var rehide = false;
if (this.targetConnection && superiorConnection.hidden_) {
superiorConnection.unhideAll();
var renderedBlock = superiorConnection.targetBlock();
renderedBlock.getSvgRoot().style.display = 'block';
renderedBlock.rendered = true;
rehide = true;
}
Blockly.RenderedConnection.superClass_.disconnect.call(this);
if (rehide) {
// Set the hidden state for the connection back to true so shadow blocks
// will be hidden.
superiorConnection.setHidden(true);
}
Blockly.RenderedConnection.superClass_.disconnect.call(this);
};
/**