From 801867f34e74e187b21d93e30a8cd1ccc1fc59ba Mon Sep 17 00:00:00 2001 From: jschanker Date: Wed, 24 Jan 2018 20:25:43 -0500 Subject: [PATCH 1/6] Fixed JS/PHP generators for math_number It was returning ORDER_ATOMIC for the block for any number; changed it so that it now returns ORDER_UNARY_NEGATION for negative numbers. --- generators/javascript/math.js | 4 +++- generators/php/math.js | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/generators/javascript/math.js b/generators/javascript/math.js index a31b943921b..0bd265af273 100644 --- a/generators/javascript/math.js +++ b/generators/javascript/math.js @@ -32,7 +32,9 @@ goog.require('Blockly.JavaScript'); Blockly.JavaScript['math_number'] = function(block) { // Numeric value. var code = parseFloat(block.getFieldValue('NUM')); - return [code, Blockly.JavaScript.ORDER_ATOMIC]; + var order = code >= 0 ? Blockly.JavaScript.ORDER_ATOMIC : + Blockly.JavaScript.ORDER_UNARY_NEGATION; + return [code, order]; }; Blockly.JavaScript['math_arithmetic'] = function(block) { diff --git a/generators/php/math.js b/generators/php/math.js index 7789ba8fe11..ef94196037e 100644 --- a/generators/php/math.js +++ b/generators/php/math.js @@ -32,12 +32,14 @@ goog.require('Blockly.PHP'); Blockly.PHP['math_number'] = function(block) { // Numeric value. var code = parseFloat(block.getFieldValue('NUM')); + var order = code >= 0 ? Blockly.PHP.ORDER_ATOMIC : + Blockly.PHP.ORDER_UNARY_NEGATION; if (code == Infinity) { code = 'INF'; } else if (code == -Infinity) { code = '-INF'; } - return [code, Blockly.PHP.ORDER_ATOMIC]; + return [code, order]; }; Blockly.PHP['math_arithmetic'] = function(block) { From 32264a52c045ad444701ebc8985ca33695da90cb Mon Sep 17 00:00:00 2001 From: jschanker Date: Fri, 4 Jun 2021 16:17:20 -0400 Subject: [PATCH 2/6] Remove row healing for block deletion #4832 --- core/contextmenu_items.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/core/contextmenu_items.js b/core/contextmenu_items.js index 63dbc702a15..873236ea3e2 100644 --- a/core/contextmenu_items.js +++ b/core/contextmenu_items.js @@ -479,7 +479,12 @@ Blockly.ContextMenuItems.registerDelete = function() { }, callback: function(/** @type {!Blockly.ContextMenuRegistry.Scope} */ scope) { Blockly.Events.setGroup(true); - scope.block.dispose(true, true); + if(scope.block.outputConnection) { + // Do not attempt to heal rows (https://github.com/google/blockly/issues/4832) + scope.block.dispose(false, true); + } else { + scope.block.dispose(true, true); + } Blockly.Events.setGroup(false); }, scopeType: Blockly.ContextMenuRegistry.ScopeType.BLOCK, From 3cc57449212cac15375b78fa53fe1f6a05ee4eca Mon Sep 17 00:00:00 2001 From: jschanker Date: Fri, 4 Jun 2021 18:39:06 -0400 Subject: [PATCH 3/6] Remove row healing for context menu block deletion * Resolves https://github.com/google/blockly/issues/4832 * Fixed lint error (missing space between if and open parenthesis) --- core/contextmenu_items.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/contextmenu_items.js b/core/contextmenu_items.js index 873236ea3e2..b61d9826227 100644 --- a/core/contextmenu_items.js +++ b/core/contextmenu_items.js @@ -479,7 +479,7 @@ Blockly.ContextMenuItems.registerDelete = function() { }, callback: function(/** @type {!Blockly.ContextMenuRegistry.Scope} */ scope) { Blockly.Events.setGroup(true); - if(scope.block.outputConnection) { + if (scope.block.outputConnection) { // Do not attempt to heal rows (https://github.com/google/blockly/issues/4832) scope.block.dispose(false, true); } else { From 9567b4cd2b411b9a426bb39002ff484a32ea2d78 Mon Sep 17 00:00:00 2001 From: jschanker Date: Tue, 8 Jun 2021 18:33:28 -0400 Subject: [PATCH 4/6] Update Blockly.deleteBlock to remove row healing --- core/blockly.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/core/blockly.js b/core/blockly.js index 81c21fde422..e889cb84074 100644 --- a/core/blockly.js +++ b/core/blockly.js @@ -216,7 +216,12 @@ Blockly.deleteBlock = function(selected) { if (!selected.workspace.isFlyout) { Blockly.Events.setGroup(true); Blockly.hideChaff(); - selected.dispose(/* heal */ true, true); + if (selected.outputConnection) { + // Do not attempt to heal rows (https://github.com/google/blockly/issues/4832) + selected.dispose(false, true); + } else { + selected.dispose(/* heal */ true, true); + } Blockly.Events.setGroup(false); } }; From 83d295b140ae0ce862beeb01d33670646365779d Mon Sep 17 00:00:00 2001 From: jschanker Date: Tue, 8 Jun 2021 18:40:40 -0400 Subject: [PATCH 5/6] Replace block deletion code with deleteBlock call ...which now contains the logic for deleting a block without attempted row healing --- core/contextmenu_items.js | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/core/contextmenu_items.js b/core/contextmenu_items.js index b61d9826227..abc7b9d8ffe 100644 --- a/core/contextmenu_items.js +++ b/core/contextmenu_items.js @@ -479,12 +479,7 @@ Blockly.ContextMenuItems.registerDelete = function() { }, callback: function(/** @type {!Blockly.ContextMenuRegistry.Scope} */ scope) { Blockly.Events.setGroup(true); - if (scope.block.outputConnection) { - // Do not attempt to heal rows (https://github.com/google/blockly/issues/4832) - scope.block.dispose(false, true); - } else { - scope.block.dispose(true, true); - } + Blockly.deleteBlock(scope.block); Blockly.Events.setGroup(false); }, scopeType: Blockly.ContextMenuRegistry.ScopeType.BLOCK, From c82f41b919432b3967c7d7f39ac89029c865a8d2 Mon Sep 17 00:00:00 2001 From: jschanker Date: Tue, 8 Jun 2021 18:54:39 -0400 Subject: [PATCH 6/6] Replace block deletion code with deleteBlock call ...which now contains the logic for deleting a block without attempted row healing --- core/contextmenu_items.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/core/contextmenu_items.js b/core/contextmenu_items.js index abc7b9d8ffe..b4adeb2f70e 100644 --- a/core/contextmenu_items.js +++ b/core/contextmenu_items.js @@ -479,7 +479,9 @@ Blockly.ContextMenuItems.registerDelete = function() { }, callback: function(/** @type {!Blockly.ContextMenuRegistry.Scope} */ scope) { Blockly.Events.setGroup(true); - Blockly.deleteBlock(scope.block); + if (scope.block) { + Blockly.deleteBlock(scope.block); + } Blockly.Events.setGroup(false); }, scopeType: Blockly.ContextMenuRegistry.ScopeType.BLOCK,