From 4b9fc09fedb7eaf9e9b257d4cfca7b6c3e156287 Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Mon, 14 Aug 2017 15:34:44 -0700 Subject: [PATCH] Code cleanup in BlockSvg.prototype.tab (#1277) --- core/block_svg.js | 43 ++++++++++++++++++++++++++----------------- 1 file changed, 26 insertions(+), 17 deletions(-) diff --git a/core/block_svg.js b/core/block_svg.js index 79bfb942a..b781d61e6 100644 --- a/core/block_svg.js +++ b/core/block_svg.js @@ -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} 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.