From c8a98bb2663b05ce71f90f4f6dc2d749c859f5c0 Mon Sep 17 00:00:00 2001 From: Monica Kozbial Date: Thu, 23 Jan 2020 13:10:33 -0800 Subject: [PATCH] Editable field spacing (#3635) * Substituting checks for isEditable. * Add isField checks. * Add parentheses for casting. * Update value of isEditable and use for spacing. * Changing to double equals. --- core/renderers/geras/info.js | 20 ++++++++++++-------- core/renderers/measurables/row_elements.js | 2 +- core/renderers/thrasos/info.js | 20 ++++++++++++-------- 3 files changed, 25 insertions(+), 17 deletions(-) diff --git a/core/renderers/geras/info.js b/core/renderers/geras/info.js index 2058e874e..7fe68853d 100644 --- a/core/renderers/geras/info.js +++ b/core/renderers/geras/info.js @@ -172,7 +172,8 @@ Blockly.geras.RenderInfo.prototype.addElemSpacing_ = function() { Blockly.geras.RenderInfo.prototype.getInRowSpacing_ = function(prev, next) { if (!prev) { // Between an editable field and the beginning of the row. - if (next && Blockly.blockRendering.Types.isField(next) && next.isEditable) { + if (next && Blockly.blockRendering.Types.isField(next) && + (/** @type Blockly.blockRendering.Field */ (next)).isEditable) { return this.constants_.MEDIUM_PADDING; } // Inline input at the beginning of the row. @@ -190,7 +191,8 @@ Blockly.geras.RenderInfo.prototype.getInRowSpacing_ = function(prev, next) { if (!Blockly.blockRendering.Types.isInput(prev) && (!next || Blockly.blockRendering.Types.isStatementInput(next))) { // Between an editable field and the end of the row. - if (Blockly.blockRendering.Types.isField(prev) && prev.isEditable) { + if (Blockly.blockRendering.Types.isField(prev) && + (/** @type Blockly.blockRendering.Field */ (prev)).isEditable) { return this.constants_.MEDIUM_PADDING; } // Padding at the end of an icon-only row to make the block shape clearer. @@ -231,7 +233,8 @@ Blockly.geras.RenderInfo.prototype.getInRowSpacing_ = function(prev, next) { if (!Blockly.blockRendering.Types.isInput(prev) && next && Blockly.blockRendering.Types.isInput(next)) { // Between an editable field and an input. - if (prev.isEditable) { + if (Blockly.blockRendering.Types.isField(prev) && + (/** @type Blockly.blockRendering.Field */ (prev)).isEditable) { if (Blockly.blockRendering.Types.isInlineInput(next)) { return this.constants_.SMALL_PADDING; } else if (Blockly.blockRendering.Types.isExternalInput(next)) { @@ -257,9 +260,9 @@ Blockly.geras.RenderInfo.prototype.getInRowSpacing_ = function(prev, next) { // Spacing between an inline input and a field. if (Blockly.blockRendering.Types.isInlineInput(prev) && - next && !Blockly.blockRendering.Types.isInput(next)) { + next && Blockly.blockRendering.Types.isField(next)) { // Editable field after inline input. - if (next.isEditable) { + if ((/** @type Blockly.blockRendering.Field */ (next)).isEditable) { return this.constants_.MEDIUM_PADDING; } else { // Noneditable field after inline input. @@ -298,9 +301,10 @@ Blockly.geras.RenderInfo.prototype.getInRowSpacing_ = function(prev, next) { } // Spacing between two fields of the same editability. - if (!Blockly.blockRendering.Types.isInput(prev) && - next && !Blockly.blockRendering.Types.isInput(next) && - (prev.isEditable == next.isEditable)) { + if (Blockly.blockRendering.Types.isField(prev) && + next && Blockly.blockRendering.Types.isField(next) && + ((/** @type Blockly.blockRendering.Field */ (prev)).isEditable == + (/** @type Blockly.blockRendering.Field */ (next)).isEditable)) { return this.constants_.LARGE_PADDING; } diff --git a/core/renderers/measurables/row_elements.js b/core/renderers/measurables/row_elements.js index c445ce6b0..095449c05 100644 --- a/core/renderers/measurables/row_elements.js +++ b/core/renderers/measurables/row_elements.js @@ -91,7 +91,7 @@ Blockly.utils.object.inherits(Blockly.blockRendering.JaggedEdge, Blockly.blockRendering.Field = function(constants, field, parentInput) { Blockly.blockRendering.Field.superClass_.constructor.call(this, constants); this.field = field; - this.isEditable = field.isCurrentlyEditable(); + this.isEditable = field.EDITABLE; this.flipRtl = field.getFlipRtl(); this.type |= Blockly.blockRendering.Types.FIELD; diff --git a/core/renderers/thrasos/info.js b/core/renderers/thrasos/info.js index 9589ef27f..25014a805 100644 --- a/core/renderers/thrasos/info.js +++ b/core/renderers/thrasos/info.js @@ -114,7 +114,8 @@ Blockly.thrasos.RenderInfo.prototype.addElemSpacing_ = function() { Blockly.thrasos.RenderInfo.prototype.getInRowSpacing_ = function(prev, next) { if (!prev) { // Between an editable field and the beginning of the row. - if (next && Blockly.blockRendering.Types.isField(next) && next.isEditable) { + if (next && Blockly.blockRendering.Types.isField(next) && + (/** @type Blockly.blockRendering.Field */ (next)).isEditable) { return this.constants_.MEDIUM_PADDING; } // Inline input at the beginning of the row. @@ -131,7 +132,8 @@ Blockly.thrasos.RenderInfo.prototype.getInRowSpacing_ = function(prev, next) { // Spacing between a non-input and the end of the row. if (!Blockly.blockRendering.Types.isInput(prev) && !next) { // Between an editable field and the end of the row. - if (Blockly.blockRendering.Types.isField(prev) && prev.isEditable) { + if (Blockly.blockRendering.Types.isField(prev) && + (/** @type Blockly.blockRendering.Field */ (prev)).isEditable) { return this.constants_.MEDIUM_PADDING; } // Padding at the end of an icon-only row to make the block shape clearer. @@ -172,7 +174,8 @@ Blockly.thrasos.RenderInfo.prototype.getInRowSpacing_ = function(prev, next) { if (!Blockly.blockRendering.Types.isInput(prev) && next && Blockly.blockRendering.Types.isInput(next)) { // Between an editable field and an input. - if (prev.isEditable) { + if (Blockly.blockRendering.Types.isField(prev) && + (/** @type Blockly.blockRendering.Field */ (prev)).isEditable) { if (Blockly.blockRendering.Types.isInlineInput(next)) { return this.constants_.SMALL_PADDING; } else if (Blockly.blockRendering.Types.isExternalInput(next)) { @@ -198,9 +201,9 @@ Blockly.thrasos.RenderInfo.prototype.getInRowSpacing_ = function(prev, next) { // Spacing between an inline input and a field. if (Blockly.blockRendering.Types.isInlineInput(prev) && - next && !Blockly.blockRendering.Types.isInput(next)) { + next && Blockly.blockRendering.Types.isField(next)) { // Editable field after inline input. - if (next.isEditable) { + if ((/** @type Blockly.blockRendering.Field */ (next)).isEditable) { return this.constants_.MEDIUM_PADDING; } else { // Noneditable field after inline input. @@ -226,9 +229,10 @@ Blockly.thrasos.RenderInfo.prototype.getInRowSpacing_ = function(prev, next) { } // Spacing between two fields of the same editability. - if (!Blockly.blockRendering.Types.isInput(prev) && - next && !Blockly.blockRendering.Types.isInput(next) && - (prev.isEditable == next.isEditable)) { + if (Blockly.blockRendering.Types.isField(prev) && + next && Blockly.blockRendering.Types.isField(next) && + ((/** @type Blockly.blockRendering.Field */ (prev)).isEditable == + (/** @type Blockly.blockRendering.Field */ (next)).isEditable)) { return this.constants_.LARGE_PADDING; }