From 917b8ff54207c135240c0d19199431dabb441f65 Mon Sep 17 00:00:00 2001 From: Neil Fraser Date: Wed, 2 Nov 2016 17:11:41 -0700 Subject: [PATCH] Lint and style tweaks. --- core/field.js | 5 +++-- core/field_dropdown.js | 17 ++++++++++++----- core/field_variable.js | 8 ++++---- core/flyout_button.js | 2 +- 4 files changed, 20 insertions(+), 12 deletions(-) diff --git a/core/field.js b/core/field.js index 73f0bc45c..4d6c0a43b 100644 --- a/core/field.js +++ b/core/field.js @@ -403,8 +403,6 @@ Blockly.Field.prototype.updateTextNode_ = function() { // Truncate displayed string and add an ellipsis ('...'). text = text.substring(0, this.maxDisplayLength - 2) + '\u2026'; } - // Empty the text element. - goog.dom.removeChildren(/** @type {!Element} */ (this.textElement_)); // Replace whitespace with non-breaking spaces so the text doesn't collapse. text = text.replace(/\s/g, Blockly.Field.NBSP); if (this.sourceBlock_.RTL && text) { @@ -415,6 +413,9 @@ Blockly.Field.prototype.updateTextNode_ = function() { // Prevent the field from disappearing if empty. text = Blockly.Field.NBSP; } + + // Replace the text. + goog.dom.removeChildren(/** @type {!Element} */ (this.textElement_)); var textNode = document.createTextNode(text); this.textElement_.appendChild(textNode); diff --git a/core/field_dropdown.js b/core/field_dropdown.js index 36b1d2513..be44fff35 100644 --- a/core/field_dropdown.js +++ b/core/field_dropdown.js @@ -75,6 +75,13 @@ Blockly.FieldDropdown.ARROW_CHAR = goog.userAgent.ANDROID ? '\u25BC' : '\u25BE'; */ Blockly.FieldDropdown.prototype.CURSOR = 'default'; +/** + * Language-neutral currently selected string. + * @type {string} + * @private + */ +Blockly.FieldDropdown.prototype.value_ = ''; + /** * Install this dropdown on a block. */ @@ -85,9 +92,9 @@ Blockly.FieldDropdown.prototype.init = function() { } // Add dropdown arrow: "option ▾" (LTR) or "▾ אופציה" (RTL) this.arrow_ = Blockly.createSvgElement('tspan', {}, null); - this.arrow_.appendChild(document.createTextNode( - this.sourceBlock_.RTL ? Blockly.FieldDropdown.ARROW_CHAR + ' ' : - ' ' + Blockly.FieldDropdown.ARROW_CHAR)); + this.arrow_.appendChild(document.createTextNode(this.sourceBlock_.RTL ? + Blockly.FieldDropdown.ARROW_CHAR + ' ' : + ' ' + Blockly.FieldDropdown.ARROW_CHAR)); Blockly.FieldDropdown.superClass_.init.call(this); // Force a reset of the text to add the arrow. @@ -188,8 +195,8 @@ Blockly.FieldDropdown.prototype.showEditor_ = function() { /** * Handle the selection of an item in the dropdown menu. - * @param {goog.ui.Menu} menu The Menu component clicked. - * @param {goog.ui.MenuItem} menuItem The MenuItem selected within menu. + * @param {!goog.ui.Menu} menu The Menu component clicked. + * @param {!goog.ui.MenuItem} menuItem The MenuItem selected within menu. */ Blockly.FieldDropdown.prototype.onItemSelected = function(menu, menuItem) { var value = menuItem.getValue(); diff --git a/core/field_variable.js b/core/field_variable.js index 661c24459..1ffd880c1 100644 --- a/core/field_variable.js +++ b/core/field_variable.js @@ -147,8 +147,8 @@ Blockly.FieldVariable.dropdownCreate = function() { * Handle the selection of an item in the variable dropdown menu. * Special case the 'Rename variable...' and 'Delete variable...' options. * In the rename case, prompt the user for a new name. - * @param {goog.ui.Menu} menu The Menu component clicked. - * @param {goog.ui.MenuItem} menuItem The MenuItem selected within menu. + * @param {!goog.ui.Menu} menu The Menu component clicked. + * @param {!goog.ui.MenuItem} menuItem The MenuItem selected within menu. */ Blockly.FieldVariable.prototype.onItemSelected = function(menu, menuItem) { var menuLength = menu.getChildCount(); @@ -157,7 +157,7 @@ Blockly.FieldVariable.prototype.onItemSelected = function(menu, menuItem) { var workspace = this.sourceBlock_.workspace; if (this.renameVarItemIndex_ >= 0 && menu.getChildAt(this.renameVarItemIndex_) === menuItem) { - // Rename variable + // Rename variable. var oldName = this.getText(); Blockly.hideChaff(); Blockly.Variables.promptName( @@ -170,7 +170,7 @@ Blockly.FieldVariable.prototype.onItemSelected = function(menu, menuItem) { return; } else if (this.deleteVarItemIndex_ >= 0 && menu.getChildAt(this.deleteVarItemIndex_) === menuItem) { - // Delete variable + // Delete variable. workspace.deleteVariable(this.getText()); return; } diff --git a/core/flyout_button.js b/core/flyout_button.js index 212c6ad21..c0bd87faf 100644 --- a/core/flyout_button.js +++ b/core/flyout_button.js @@ -123,7 +123,7 @@ Blockly.FlyoutButton.prototype.createDom = function() { this.svgGroup_); var svgText = Blockly.createSvgElement('text', - {'class': this.isLabel_ ? 'blocklyFlyoutLabelText' : 'blocklyText', + {'class': this.isLabel_ ? 'blocklyFlyoutLabelText' : 'blocklyText', 'x': 0, 'y': 0, 'text-anchor': 'middle'}, this.svgGroup_); svgText.textContent = this.text_;