mirror of
https://github.com/google/blockly.git
synced 2026-01-10 10:27:08 +01:00
Check if a type exists before testing instanceof (#3031)
* Check if a type exists before instance of
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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');
|
||||
|
||||
|
||||
@@ -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_;
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user