Merge pull request #1752 from samelhusseini/develop_unplugblock

Snap a single block from a stack (if meta key is pressed)
This commit is contained in:
Rachel Fenichel
2018-04-02 09:27:09 -07:00
committed by GitHub
2 changed files with 16 additions and 4 deletions

View File

@@ -144,9 +144,10 @@ Blockly.BlockDragger.initIconData_ = function(block) {
* Start dragging a block. This includes moving it to the drag surface.
* @param {!goog.math.Coordinate} currentDragDeltaXY How far the pointer has
* moved from the position at mouse down, in pixel units.
* @param {boolean} healStack whether or not to heal the stack after disconnecting
* @package
*/
Blockly.BlockDragger.prototype.startBlockDrag = function(currentDragDeltaXY) {
Blockly.BlockDragger.prototype.startBlockDrag = function(currentDragDeltaXY, healStack) {
if (!Blockly.Events.getGroup()) {
Blockly.Events.setGroup(true);
}
@@ -154,8 +155,10 @@ Blockly.BlockDragger.prototype.startBlockDrag = function(currentDragDeltaXY) {
this.workspace_.setResizesEnabled(false);
Blockly.BlockSvg.disconnectUiStop_();
if (this.draggingBlock_.getParent()) {
this.draggingBlock_.unplug();
if (this.draggingBlock_.getParent() ||
(healStack && this.draggingBlock_.nextConnection &&
this.draggingBlock_.nextConnection.targetBlock())) {
this.draggingBlock_.unplug(healStack);
var delta = this.pixelsToWorkspaceUnits_(currentDragDeltaXY);
var newLoc = goog.math.Coordinate.sum(this.startXY_, delta);

View File

@@ -225,6 +225,14 @@ Blockly.Gesture = function(e, creatorWorkspace) {
* @private
*/
this.isEnding_ = false;
/**
* Boolean used to indicate whether or not to heal the stack after
* disconnecting a block.
* @type {boolean}
* @private
*/
this.healStack_ = !Blockly.DRAG_STACK;
};
/**
@@ -443,7 +451,7 @@ Blockly.Gesture.prototype.updateIsDragging_ = function() {
Blockly.Gesture.prototype.startDraggingBlock_ = function() {
this.blockDragger_ = new Blockly.BlockDragger(this.targetBlock_,
this.startWorkspace_);
this.blockDragger_.startBlockDrag(this.currentDragDeltaXY_);
this.blockDragger_.startBlockDrag(this.currentDragDeltaXY_, this.healStack_);
this.blockDragger_.dragBlock(this.mostRecentEvent_,
this.currentDragDeltaXY_);
};
@@ -503,6 +511,7 @@ Blockly.Gesture.prototype.doStart = function(e) {
}
this.mouseDownXY_ = new goog.math.Coordinate(e.clientX, e.clientY);
this.healStack_ = e.altKey || e.ctrlKey || e.metaKey;
this.bindMouseEvents(e);
};