Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions core/block_dragger.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,16 +228,11 @@ Blockly.BlockDragger.prototype.fireDragStartEvent_ = function() {
Blockly.BlockDragger.prototype.drag = function(e, currentDragDeltaXY) {
var delta = this.pixelsToWorkspaceUnits_(currentDragDeltaXY);
var newLoc = Blockly.utils.Coordinate.sum(this.startXY_, delta);

this.draggingBlock_.moveDuringDrag(newLoc);
this.dragIcons_(delta);

var oldDragTarget = this.dragTarget_;
this.dragTarget_ = this.workspace_.getDragTarget(e);
if (this.dragTarget_ !== oldDragTarget) {
oldDragTarget && oldDragTarget.onDragExit();
this.dragTarget_ && this.dragTarget_.onDragEnter();
}

this.draggedConnectionManager_.update(delta, this.dragTarget_);
var oldWouldDeleteBlock = this.wouldDeleteBlock_;
Expand All @@ -246,6 +241,14 @@ Blockly.BlockDragger.prototype.drag = function(e, currentDragDeltaXY) {
// Prevent unnecessary add/remove class calls.
this.updateCursorDuringBlockDrag_();
}

// Call drag enter/exit/over after wouldDeleteBlock is called in
// InsertionMarkerManager.update.
if (this.dragTarget_ !== oldDragTarget) {
oldDragTarget && oldDragTarget.onDragExit();
this.dragTarget_ && this.dragTarget_.onDragEnter();
}
this.dragTarget_ && this.dragTarget_.onDragOver();
};

/**
Expand Down
15 changes: 7 additions & 8 deletions core/bubble_dragger.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,22 +132,23 @@ Blockly.BubbleDragger.prototype.startBubbleDrag = function() {
Blockly.BubbleDragger.prototype.dragBubble = function(e, currentDragDeltaXY) {
var delta = this.pixelsToWorkspaceUnits_(currentDragDeltaXY);
var newLoc = Blockly.utils.Coordinate.sum(this.startXY_, delta);

this.draggingBubble_.moveDuringDrag(this.dragSurface_, newLoc);

var oldDragTarget = this.dragTarget_;
this.dragTarget_ = this.workspace_.getDragTarget(e);
if (this.dragTarget_ !== oldDragTarget) {
oldDragTarget && oldDragTarget.onDragExit();
this.dragTarget_ && this.dragTarget_.onDragEnter();
}

var oldWouldDeleteBubble = this.wouldDeleteBubble_;
this.wouldDeleteBubble_ = this.shouldDelete_(this.dragTarget_);
if (oldWouldDeleteBubble != this.wouldDeleteBubble_) {
// Prevent unnecessary add/remove class calls.
this.updateCursorDuringBubbleDrag_();
}

if (this.dragTarget_ !== oldDragTarget) {
oldDragTarget && oldDragTarget.onDragExit();
this.dragTarget_ && this.dragTarget_.onDragEnter();
}
this.dragTarget_ && this.dragTarget_.onDragOver();
};

/**
Expand All @@ -159,9 +160,7 @@ Blockly.BubbleDragger.prototype.dragBubble = function(e, currentDragDeltaXY) {
* @private
*/
Blockly.BubbleDragger.prototype.shouldDelete_ = function(dragTarget) {
var couldDeleteBubble = this.draggingBubble_.isDeletable();

if (couldDeleteBubble && dragTarget) {
if (dragTarget) {
var componentManager = this.workspace_.getComponentManager();
var isDeleteArea = componentManager.hasCapability(dragTarget.id,
Blockly.ComponentManager.Capability.DELETE_AREA);
Expand Down
27 changes: 21 additions & 6 deletions core/delete_area.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,27 +27,42 @@ goog.require('Blockly.IDeleteArea');
*/
Blockly.DeleteArea = function() {
Blockly.DeleteArea.superClass_.constructor.call(this);

/**
* Whether the current block or bubble dragged over this delete area would be
* deleted if dropped on this component.
* @type {boolean}
* @protected
*/
this.wouldDelete_ = false;
};
Blockly.utils.object.inherits(Blockly.DeleteArea, Blockly.DragTarget);

/**
* Returns whether the provided block would be deleted if dropped on this area.
* @param {!Blockly.BlockSvg} _block The block.
* This method should check if the block is deletable and is always called
* before onDragEnter/onDragOver/onDragExit.
* @param {!Blockly.BlockSvg} block The block.
* @param {boolean} couldConnect Whether the block could could connect to
* another.
* @return {boolean} Whether the block provided would be deleted if dropped on
* this area.
*/
Blockly.DeleteArea.prototype.wouldDeleteBlock = function(_block, couldConnect) {
return !couldConnect;
Blockly.DeleteArea.prototype.wouldDeleteBlock = function(block, couldConnect) {
var couldDeleteBlock = !block.getParent() && block.isDeletable();
this.wouldDelete_ = couldDeleteBlock && !couldConnect;
return this.wouldDelete_;
};

/**
* Returns whether the provided bubble would be deleted if dropped on this area.
* @param {!Blockly.IBubble} _bubble The bubble.
* This method should check if the bubble is deletable and is always called
* before onDragEnter/onDragOver/onDragExit.
* @param {!Blockly.IBubble} bubble The bubble.
* @return {boolean} Whether the bubble provided would be deleted if dropped on
* this area.
*/
Blockly.DeleteArea.prototype.wouldDeleteBubble = function(_bubble) {
return true;
Blockly.DeleteArea.prototype.wouldDeleteBubble = function(bubble) {
this.wouldDelete_ = bubble.isDeletable();
return this.wouldDelete_;
};
8 changes: 8 additions & 0 deletions core/drag_target.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ Blockly.DragTarget.prototype.onDragEnter = function() {
// no-op
};

/**
* Handles when a cursor with a block or bubble is dragged over this drag
* target.
*/
Blockly.DragTarget.prototype.onDragOver = function() {
// no-op
};

/**
* Handles when a cursor with a block or bubble exits this drag target.
*/
Expand Down
5 changes: 1 addition & 4 deletions core/insertion_marker_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -456,10 +456,7 @@ Blockly.InsertionMarkerManager.prototype.getStartRadius_ = function() {
*/
Blockly.InsertionMarkerManager.prototype.shouldDelete_ = function(
candidate, dragTarget) {
var couldDeleteBlock =
!this.topBlock_.getParent() && this.topBlock_.isDeletable();

if (couldDeleteBlock && dragTarget) {
if (dragTarget) {
var componentManager = this.workspace_.getComponentManager();
var isDeleteArea = componentManager.hasCapability(dragTarget.id,
Blockly.ComponentManager.Capability.DELETE_AREA);
Expand Down
4 changes: 4 additions & 0 deletions core/interfaces/i_delete_area.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ Blockly.IDeleteArea = function() {};

/**
* Returns whether the provided block would be deleted if dropped on this area.
* This method should check if the block is deletable and is always called
* before onDragEnter/onDragOver/onDragExit.
* @param {!Blockly.BlockSvg} block The block.
* @param {boolean} couldConnect Whether the block could could connect to
* another.
Expand All @@ -40,6 +42,8 @@ Blockly.IDeleteArea.prototype.wouldDeleteBlock;

/**
* Returns whether the provided bubble would be deleted if dropped on this area.
* This method should check if the bubble is deletable and is always called
* before onDragEnter/onDragOver/onDragExit.
* @param {!Blockly.IBubble} bubble The bubble.
* @return {boolean} Whether the bubble provided would be deleted if dropped on
* this area.
Expand Down
7 changes: 7 additions & 0 deletions core/interfaces/i_drag_target.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ Blockly.IDragTarget.prototype.getClientRect;
*/
Blockly.IDragTarget.prototype.onDragEnter;

/**
* Handles when a cursor with a block or bubble is dragged over this drag
* target.
*/
Blockly.IDragTarget.prototype.onDragOver;


/**
* Handles when a cursor with a block or bubble exits this drag target.
*/
Expand Down
10 changes: 7 additions & 3 deletions core/toolbox/toolbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -541,15 +541,19 @@ Blockly.Toolbox.prototype.getClientRect = function() {

/**
* Returns whether the provided block would be deleted if dropped on this area.
* @param {!Blockly.BlockSvg} _block The block.
* This method should check if the block is deletable and is always called
* before onDragEnter/onDragOver/onDragExit.
* @param {!Blockly.BlockSvg} block The block.
* @param {boolean} _couldConnect Whether the block could could connect to
* another.
* @return {boolean} Whether the block provided would be deleted if dropped on
* this area.
* @override
*/
Blockly.Toolbox.prototype.wouldDeleteBlock = function(_block, _couldConnect) {
Blockly.Toolbox.prototype.wouldDeleteBlock = function(block, _couldConnect) {
// Prefer dragging to the toolbox over connecting to other blocks.
return true;
this.wouldDelete_ = !block.getParent() && block.isDeletable();
return this.wouldDelete_;
};

/**
Expand Down
22 changes: 13 additions & 9 deletions core/trashcan.js
Original file line number Diff line number Diff line change
Expand Up @@ -533,39 +533,43 @@ Blockly.Trashcan.prototype.getClientRect = function() {
};

/**
* Handles when a cursor with a block or bubble enters this drag target.
* Handles when a cursor with a block or bubble is dragged over this drag
* target.
* @override
*/
Blockly.Trashcan.prototype.onDragEnter = function() {
this.setLidOpen(true);
Blockly.Trashcan.prototype.onDragOver = function() {
Blockly.Trashcan.superClass_.onDragOver.call(this);
this.setLidOpen(this.wouldDelete_);
};

/**
* Handles when a cursor with a block or bubble exits this drag target.
* @override
*/
Blockly.Trashcan.prototype.onDragExit = function() {
Blockly.Trashcan.superClass_.onDragExit.call(this);
this.setLidOpen(false);
};


/**
* Handles when a block is dropped on this component. Should not handle delete
* here.
* @param {!Blockly.BlockSvg} _block The block.
* @param {!Blockly.BlockSvg} block The block.
* @override
*/
Blockly.Trashcan.prototype.onBlockDrop = function(_block) {
Blockly.Trashcan.prototype.onBlockDrop = function(block) {
Blockly.Trashcan.superClass_.onBlockDrop.call(this, block);
this.onDrop_();
};

/**
* Handles when a bubble is dropped on this component. Should not handle delete
* here.
* @param {!Blockly.IBubble} _bubble The bubble.
* @param {!Blockly.IBubble} bubble The bubble.
* @override
*/
Blockly.Trashcan.prototype.onBubbleDrop = function(_bubble) {
Blockly.Trashcan.prototype.onBubbleDrop = function(bubble) {
Blockly.Trashcan.superClass_.onBubbleDrop.call(this, bubble);
this.onDrop_();
};

Expand All @@ -574,7 +578,7 @@ Blockly.Trashcan.prototype.onBubbleDrop = function(_bubble) {
* @private
*/
Blockly.Trashcan.prototype.onDrop_ = function() {
setTimeout(this.closeLid.bind(this), 100);
setTimeout(this.setLidOpen.bind(this, false), 100);
};

/**
Expand Down