Slightly less fragile

This commit is contained in:
Rachel Fenichel
2019-08-21 15:24:37 -07:00
parent d19614439f
commit dd9fdf908f
2 changed files with 16 additions and 5 deletions

View File

@@ -482,11 +482,24 @@ Blockly.blockRendering.InputRow.prototype.measure = function() {
this.widthWithConnectedBlocks = this.width + connectedBlockWidths;
};
/**
* @override
*/
Blockly.blockRendering.InputRow.prototype.getLastSpacer = function() {
// Adding spacing after the input connection would look weird. Find the
// before the last input connection and add it there instead.
if (this.hasExternalInput || this.hasStatement) {
var spacer = this.elements[this.elements.length - 3];
return /** @type {Blockly.blockRendering.InRowSpacer} */ (spacer);
var elems = this.elements;
for (var i = elems.length - 1, elem; (elem = elems[i]); i--) {
if (elem.isSpacer()) {
continue;
}
if (elem.isInput) {
var spacer = elems[i - 1];
return /** @type {Blockly.blockRendering.InRowSpacer} */ (spacer);
}
}
}
return Blockly.blockRendering.InputRow.superClass_.getLastSpacer.call(this);
};

View File

@@ -253,14 +253,12 @@ Blockly.thrasos.RenderInfo.prototype.alignRowElements_ = function() {
* @override
*/
Blockly.thrasos.RenderInfo.prototype.addAlignmentPadding_ = function(row, missingSpace) {
var elems = row.elements;
var input = row.getLastInput();
if (input) {
var firstSpacer = row.getFirstSpacer();
var lastSpacer = row.getLastSpacer();
if (row.hasExternalInput || row.hasStatement) {
// Get the spacer right before the input socket.
lastSpacer = elems[elems.length - 3];
row.widthWithConnectedBlocks += missingSpace;
}
// Decide where the extra padding goes.