Code cleanup in BlockSvg.prototype.tab (#1277)

This commit is contained in:
Rachel Fenichel
2017-08-14 15:34:44 -07:00
committed by GitHub
parent a6245f4c6e
commit 4b9fc09fed

View File

@@ -503,23 +503,7 @@ Blockly.BlockSvg.prototype.setCollapsed = function(collapsed) {
* @param {boolean} forward If true go forward, otherwise backward.
*/
Blockly.BlockSvg.prototype.tab = function(start, forward) {
// This function need not be efficient since it runs once on a keypress.
// Create an ordered list of all text fields and connected inputs.
var list = [];
for (var i = 0, input; input = this.inputList[i]; i++) {
for (var j = 0, field; field = input.fieldRow[j]; j++) {
if (field instanceof Blockly.FieldTextInput) {
// TODO: Also support dropdown fields.
list.push(field);
}
}
if (input.connection) {
var block = input.connection.targetBlock();
if (block) {
list.push(block);
}
}
}
var list = this.createTabList_();
var i = list.indexOf(start);
if (i == -1) {
// No start location, start at the beginning or end.
@@ -539,6 +523,31 @@ Blockly.BlockSvg.prototype.tab = function(start, forward) {
}
};
/**
* Create an ordered list of all text fields and connected inputs.
* @return {!Array<!Blockly.FieldTextInput|!Blockly.Input>} The ordered list.
* @private
*/
Blockly.BlockSvg.prototype.createTabList_ = function() {
// This function need not be efficient since it runs once on a keypress.
var list = [];
for (var i = 0, input; input = this.inputList[i]; i++) {
for (var j = 0, field; field = input.fieldRow[j]; j++) {
if (field instanceof Blockly.FieldTextInput) {
// TODO(# 1276): Also support dropdown fields.
list.push(field);
}
}
if (input.connection) {
var block = input.connection.targetBlock();
if (block) {
list.push(block);
}
}
}
return list;
};
/**
* Handle a mouse-down on an SVG block.
* @param {!Event} e Mouse down event or touch start event.