Check if a type exists before testing instanceof (#3031)

* Check if a type exists before instance of
This commit is contained in:
Sam El-Husseini
2019-09-17 16:28:18 -07:00
committed by GitHub
parent 99c624db34
commit 8fae0411f7
7 changed files with 34 additions and 12 deletions

View File

@@ -1338,11 +1338,7 @@ Blockly.Block.prototype.toString = function(opt_maxLength, opt_emptyToken) {
} else {
for (var i = 0, input; input = this.inputList[i]; i++) {
for (var j = 0, field; field = input.fieldRow[j]; j++) {
if (field instanceof Blockly.FieldDropdown && !field.getValue()) {
text.push(emptyFieldPlaceholder);
} else {
text.push(field.getText());
}
text.push(field.getText());
}
if (input.connection) {
var child = input.connection.targetBlock();

View File

@@ -632,8 +632,7 @@ Blockly.BlockSvg.prototype.createTabList_ = function() {
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 && field.isVisible()) {
// TODO (#1276): Also support dropdown fields.
if (field.isTabNavigable() && field.isVisible()) {
list.push(field);
}
}

View File

@@ -913,6 +913,22 @@ Blockly.Field.prototype.getParentInput = function() {
return parentInput;
};
/**
* Returns whether or not we should flip the field in RTL.
* @return {boolean} True if we should flip in RTL.
*/
Blockly.Field.prototype.getFlipRtl = function() {
return false;
};
/**
* Returns whether or not the field is tab navigable.
* @return {boolean} True if the field is tab navigable.
*/
Blockly.Field.prototype.isTabNavigable = function() {
return false;
};
/**
* Handles the given action.
* This is only triggered when keyboard accessibility mode is enabled.

View File

@@ -35,6 +35,7 @@ goog.require('Blockly.utils.aria');
goog.require('Blockly.utils.colour');
goog.require('Blockly.utils.dom');
goog.require('Blockly.utils.IdGenerator');
goog.require('Blockly.utils.KeyCodes');
goog.require('Blockly.utils.object');
goog.require('Blockly.utils.Size');

View File

@@ -218,6 +218,7 @@ Blockly.FieldImage.prototype.doValueUpdate_ = function(newValue) {
/**
* Get whether to flip this image in RTL
* @return {boolean} True if we should flip in RTL.
* @override
*/
Blockly.FieldImage.prototype.getFlipRtl = function() {
return this.flipRtl_;

View File

@@ -35,6 +35,7 @@ goog.require('Blockly.utils');
goog.require('Blockly.utils.aria');
goog.require('Blockly.utils.Coordinate');
goog.require('Blockly.utils.dom');
goog.require('Blockly.utils.KeyCodes');
goog.require('Blockly.utils.object');
goog.require('Blockly.utils.Size');
goog.require('Blockly.utils.userAgent');
@@ -357,15 +358,14 @@ Blockly.FieldTextInput.prototype.unbindInputEvents_ = function() {
* @protected
*/
Blockly.FieldTextInput.prototype.onHtmlInputKeyDown_ = function(e) {
var tabKey = 9, enterKey = 13, escKey = 27;
if (e.keyCode == enterKey) {
if (e.keyCode == Blockly.utils.KeyCodes.ENTER) {
Blockly.WidgetDiv.hide();
Blockly.DropDownDiv.hideWithoutAnimation();
} else if (e.keyCode == escKey) {
} else if (e.keyCode == Blockly.utils.KeyCodes.ESC) {
this.htmlInput_.value = this.htmlInput_.defaultValue;
Blockly.WidgetDiv.hide();
Blockly.DropDownDiv.hideWithoutAnimation();
} else if (e.keyCode == tabKey) {
} else if (e.keyCode == Blockly.utils.KeyCodes.TAB) {
Blockly.WidgetDiv.hide();
Blockly.DropDownDiv.hideWithoutAnimation();
this.sourceBlock_.tab(this, !e.shiftKey);
@@ -479,6 +479,15 @@ Blockly.FieldTextInput.nonnegativeIntegerValidator = function(text) {
return n;
};
/**
* Returns whether or not the field is tab navigable.
* @return {boolean} True if the field is tab navigable.
* @override
*/
Blockly.FieldTextInput.prototype.isTabNavigable = function() {
return true;
};
/**
* Use the `getText_` developer hook to override the field's text representation.
* When we're currently editing, return the current html value instead.

View File

@@ -95,7 +95,7 @@ Blockly.blockRendering.Field = function(constants, field, parentInput) {
Blockly.blockRendering.Field.superClass_.constructor.call(this, constants);
this.field = field;
this.isEditable = field.isCurrentlyEditable();
this.flipRtl = field instanceof Blockly.FieldImage && field.getFlipRtl();
this.flipRtl = field.getFlipRtl();
this.type |= Blockly.blockRendering.Types.FIELD;
var size = this.field.getSize();