Accept lowercase alignment (#3359)

* Accept lowercase alignment
This commit is contained in:
Sam El-Husseini
2019-10-29 11:45:30 -07:00
committed by GitHub
parent 6df85b9ff3
commit 942068314f
4 changed files with 27 additions and 6 deletions

View File

@@ -1454,7 +1454,7 @@ Blockly.Block.prototype.jsonInit = function(json) {
var i = 0;
while (json['message' + i] !== undefined) {
this.interpolate_(json['message' + i], json['args' + i] || [],
json['lastDummyAlign' + i]);
json['lastDummyAlign' + i], warningPrefix);
i++;
}
@@ -1578,9 +1578,11 @@ Blockly.Block.prototype.mixin = function(mixinObj, opt_disableCheck) {
* @param {!Array} args Array of arguments to be interpolated.
* @param {string|undefined} lastDummyAlign If a dummy input is added at the
* end, how should it be aligned?
* @param {string} warningPrefix Warning prefix string identifying block.
* @private
*/
Blockly.Block.prototype.interpolate_ = function(message, args, lastDummyAlign) {
Blockly.Block.prototype.interpolate_ = function(message, args, lastDummyAlign,
warningPrefix) {
var tokens = Blockly.utils.tokenizeInterpolation(message);
// Interpolate the arguments. Build a list of elements.
var indexDup = [];
@@ -1625,7 +1627,8 @@ Blockly.Block.prototype.interpolate_ = function(message, args, lastDummyAlign) {
var alignmentLookup = {
'LEFT': Blockly.ALIGN_LEFT,
'RIGHT': Blockly.ALIGN_RIGHT,
'CENTRE': Blockly.ALIGN_CENTRE
'CENTRE': Blockly.ALIGN_CENTRE,
'CENTER': Blockly.ALIGN_CENTRE
};
// Populate block with inputs and fields.
var fieldStack = [];
@@ -1673,7 +1676,14 @@ Blockly.Block.prototype.interpolate_ = function(message, args, lastDummyAlign) {
input.setCheck(element['check']);
}
if (element['align']) {
input.setAlign(alignmentLookup[element['align']]);
var align = !!element['align'] && element['align'].toUpperCase();
var alignment = alignmentLookup[align];
if (alignment != undefined) {
input.setAlign(alignment);
} else {
console.warn(warningPrefix + 'Illegal align value: ',
element['align']);
}
}
for (var j = 0; j < fieldStack.length; j++) {
input.appendField(fieldStack[j][0], fieldStack[j][1]);

View File

@@ -380,7 +380,9 @@ Blockly.blockRendering.RenderInfo.prototype.addInput_ = function(input, activeRo
this.constants_.DUMMY_INPUT_MIN_HEIGHT);
activeRow.hasDummyInput = true;
}
activeRow.align = input.align;
if (activeRow.align == null) {
activeRow.align = input.align;
}
};
/**

View File

@@ -119,7 +119,9 @@ Blockly.geras.RenderInfo.prototype.addInput_ = function(input, activeRow) {
this.constants_.DUMMY_INPUT_MIN_HEIGHT);
activeRow.hasDummyInput = true;
}
activeRow.align = input.align;
if (activeRow.align == null) {
activeRow.align = input.align;
}
};
/**

View File

@@ -154,6 +154,13 @@ Blockly.blockRendering.Row = function(constants) {
this.constants_ = constants;
this.notchOffset = this.constants_.NOTCH_OFFSET_LEFT;
/**
* Alignment of the row.
* @package
* @type {?number}
*/
this.align = null;
};
/**