From 57852f0249f87f2ebec0754725ee682711be1b64 Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Thu, 8 Feb 2018 17:23:22 -0800 Subject: [PATCH 1/2] Don't allow block deletion in the flyout. Make copy-paste always copy to the main workspace. --- core/blockly.js | 18 +++++++++++++----- core/workspace_svg.js | 7 +++++++ 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/core/blockly.js b/core/blockly.js index bb1fa9759..b900cd41a 100644 --- a/core/blockly.js +++ b/core/blockly.js @@ -206,8 +206,9 @@ Blockly.onKeyDown_ = function(e) { // 'c' for copy. Blockly.hideChaff(); Blockly.copy_(Blockly.selected); - } else if (e.keyCode == 88) { - // 'x' for cut. + } else if (e.keyCode == 88 && !Blockly.selected.workspace.isFlyout) { + // 'x' for cut, but not in a flyout. + // Don't even copy the selected item in the flyout. Blockly.copy_(Blockly.selected); deleteBlock = true; } @@ -216,7 +217,13 @@ Blockly.onKeyDown_ = function(e) { // 'v' for paste. if (Blockly.clipboardXml_) { Blockly.Events.setGroup(true); - Blockly.clipboardSource_.paste(Blockly.clipboardXml_); + // Pasting always pastes to the main workspace, even if the copy started + // in a flyout workspace. + var workspace = Blockly.clipboardSource_; + if (workspace.isFlyout) { + workspace = workspace.targetWorkspace; + } + workspace.paste(Blockly.clipboardXml_); Blockly.Events.setGroup(false); } } else if (e.keyCode == 90) { @@ -225,8 +232,9 @@ Blockly.onKeyDown_ = function(e) { Blockly.mainWorkspace.undo(e.shiftKey); } } - if (deleteBlock) { - // Common code for delete and cut. + // Common code for delete and cut. + // Don't delete in the flyout. + if (deleteBlock && !Blockly.selected.workspace.isFlyout) { Blockly.Events.setGroup(true); Blockly.hideChaff(); Blockly.selected.dispose(/* heal */ true, true); diff --git a/core/workspace_svg.js b/core/workspace_svg.js index 53b600ae8..5766c3de8 100644 --- a/core/workspace_svg.js +++ b/core/workspace_svg.js @@ -267,6 +267,13 @@ Blockly.WorkspaceSvg.prototype.flyoutButtonCallbacks_ = {}; */ Blockly.WorkspaceSvg.prototype.toolboxCategoryCallbacks_ = {}; +/** + * In a flyout, the target workspace where blocks should be placed after a drag. + * Otherwise null. + * @type {?Blockly.WorkspaceSvg} + * @package + */ +Blockly.WorkspaceSvg.prototype.targetWorkspace = null; /** * Inverted screen CTM, for use in mouseToSvg. * @type {SVGMatrix} From f471a23b2b45784087bf06b2a42690404f5917fc Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Thu, 8 Feb 2018 18:08:46 -0800 Subject: [PATCH 2/2] Add comment --- core/blockly.js | 3 +++ core/workspace_svg.js | 1 + 2 files changed, 4 insertions(+) diff --git a/core/blockly.js b/core/blockly.js index b900cd41a..427d45199 100644 --- a/core/blockly.js +++ b/core/blockly.js @@ -202,6 +202,9 @@ Blockly.onKeyDown_ = function(e) { } if (Blockly.selected && Blockly.selected.isDeletable() && Blockly.selected.isMovable()) { + // Don't allow copying immovable or undeletable blocks. The next step + // would be to paste, which would create additional undeletable/immovable + // blocks on the workspace. if (e.keyCode == 67) { // 'c' for copy. Blockly.hideChaff(); diff --git a/core/workspace_svg.js b/core/workspace_svg.js index 5766c3de8..37ab8b910 100644 --- a/core/workspace_svg.js +++ b/core/workspace_svg.js @@ -274,6 +274,7 @@ Blockly.WorkspaceSvg.prototype.toolboxCategoryCallbacks_ = {}; * @package */ Blockly.WorkspaceSvg.prototype.targetWorkspace = null; + /** * Inverted screen CTM, for use in mouseToSvg. * @type {SVGMatrix}