Merge pull request #1599 from rachel-fenichel/bugfix/sb-1373

Don't allow block deletion in the flyout.  Make copy-paste always copy to the main workspace
This commit is contained in:
Rachel Fenichel
2018-02-12 14:43:40 -08:00
committed by GitHub
2 changed files with 24 additions and 5 deletions

View File

@@ -202,12 +202,16 @@ 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();
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 +220,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 +235,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);

View File

@@ -267,6 +267,14 @@ 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}