From ae39fb9e2326848478a2a977db38c616678d6c16 Mon Sep 17 00:00:00 2001 From: Neil Fraser Date: Tue, 3 Aug 2021 03:28:47 -0700 Subject: [PATCH] Add supressPrefixSuffix to if/else block Alternatively, this could be done by using an extension, rather than JSON. I have no preference. Issue #5268. --- blocks/logic.js | 8 ++------ blocks/loops.js | 7 +------ core/block.js | 6 ++++-- 3 files changed, 7 insertions(+), 14 deletions(-) diff --git a/blocks/logic.js b/blocks/logic.js index c7b6acf0c..7f977fdad 100644 --- a/blocks/logic.js +++ b/blocks/logic.js @@ -73,6 +73,7 @@ Blockly.defineBlocksWithJsonArray([ // BEGIN JSON EXTRACT "nextStatement": null, "style": "logic_blocks", "helpUrl": "%{BKY_CONTROLS_IF_HELPURL}", + "suppressPrefixSuffix": true, "mutator": "controls_if_mutator", "extensions": ["controls_if_tooltip"] }, @@ -106,6 +107,7 @@ Blockly.defineBlocksWithJsonArray([ // BEGIN JSON EXTRACT "style": "logic_blocks", "tooltip": "%{BKYCONTROLS_IF_TOOLTIP_2}", "helpUrl": "%{BKY_CONTROLS_IF_HELPURL}", + "suppressPrefixSuffix": true, "extensions": ["controls_if_tooltip"] }, // Block for comparison operator. @@ -295,12 +297,6 @@ Blockly.Constants.Logic.CONTROLS_IF_MUTATOR_MIXIN = { elseifCount_: 0, elseCount_: 0, - /** - * Don't automatically add STATEMENT_PREFIX and STATEMENT_SUFFIX to generated - * code. These will be handled manually in this block's generators. - */ - suppressPrefixSuffix: true, - /** * Create XML to represent the number of else-if and else inputs. * @return {Element} XML storage element. diff --git a/blocks/loops.js b/blocks/loops.js index 772871dba..6e7ad1997 100644 --- a/blocks/loops.js +++ b/blocks/loops.js @@ -196,6 +196,7 @@ Blockly.defineBlocksWithJsonArray([ // BEGIN JSON EXTRACT "previousStatement": null, "style": "loop_blocks", "helpUrl": "%{BKY_CONTROLS_FLOW_STATEMENTS_HELPURL}", + "suppressPrefixSuffix": true, "extensions": [ "controls_flow_tooltip", "controls_flow_in_loop_check" @@ -301,12 +302,6 @@ Blockly.Constants.Loops.CONTROL_FLOW_IN_LOOP_CHECK_MIXIN = { 'controls_whileUntil' ], - /** - * Don't automatically add STATEMENT_PREFIX and STATEMENT_SUFFIX to generated - * code. These will be handled manually in this block's generators. - */ - suppressPrefixSuffix: true, - /** * Is the given block enclosed (at any level) by a loop? * @param {!Blockly.Block} block Current block. diff --git a/core/block.js b/core/block.js index cfeaddebd..01405d021 100644 --- a/core/block.js +++ b/core/block.js @@ -1556,8 +1556,10 @@ Blockly.Block.prototype.jsonInit = function(json) { this.setTooltip(localizedText); } if (json['enableContextMenu'] !== undefined) { - var rawValue = json['enableContextMenu']; - this.contextMenu = !!rawValue; + this.contextMenu = !!json['enableContextMenu']; + } + if (json['suppressPrefixSuffix'] !== undefined) { + this.suppressPrefixSuffix = !!json['suppressPrefixSuffix']; } if (json['helpUrl'] !== undefined) { var rawValue = json['helpUrl'];