From bde1edff85bafb25d95fab3cdc7239d67a60bcdf Mon Sep 17 00:00:00 2001 From: Navil Perez Date: Thu, 17 Oct 2019 11:41:31 -0700 Subject: [PATCH 1/3] Add dragStart and dragEnd UI events --- core/block_dragger.js | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/core/block_dragger.js b/core/block_dragger.js index eca2cfbec..2fb096c1d 100644 --- a/core/block_dragger.js +++ b/core/block_dragger.js @@ -26,6 +26,7 @@ goog.provide('Blockly.BlockDragger'); goog.require('Blockly.blockAnimations'); goog.require('Blockly.Events'); goog.require('Blockly.Events.BlockMove'); +goog.require('Blockly.Events.Ui'); goog.require('Blockly.InsertionMarkerManager'); goog.require('Blockly.utils.Coordinate'); goog.require('Blockly.utils.dom'); @@ -147,6 +148,7 @@ Blockly.BlockDragger.prototype.startBlockDrag = function(currentDragDeltaXY, if (!Blockly.Events.getGroup()) { Blockly.Events.setGroup(true); } + this.fireDragStartEvent_(); // Mutators don't have the same type of z-ordering as the normal workspace // during a drag. They have to rely on the order of the blocks in the SVG. @@ -186,6 +188,16 @@ Blockly.BlockDragger.prototype.startBlockDrag = function(currentDragDeltaXY, } }; +/** + * Fire a ui event at the start of a block drag. + * @private + */ +Blockly.BlockDragger.prototype.fireDragStartEvent_ = function() { + var event = new Blockly.Events.Ui(this.draggingBlock_, 'dragStart', + null, this.draggingBlock_.getDescendants(false)); + Blockly.Events.fire(event) +}; + /** * Execute a step of block dragging, based on the given event. Update the * display accordingly. @@ -218,7 +230,8 @@ Blockly.BlockDragger.prototype.endBlockDrag = function(e, currentDragDeltaXY) { // Make sure internal state is fresh. this.dragBlock(e, currentDragDeltaXY); this.dragIconData_ = []; - + this.fireDragEndEvent_(); + Blockly.utils.dom.stopTextWidthCache(); Blockly.blockAnimations.disconnectUiStop(); @@ -252,6 +265,16 @@ Blockly.BlockDragger.prototype.endBlockDrag = function(e, currentDragDeltaXY) { Blockly.Events.setGroup(false); }; +/** + * Fire a ui event at the end of a block drag. + * @private + */ +Blockly.BlockDragger.prototype.fireDragEndEvent_ = function() { + var event = new Blockly.Events.Ui(this.draggingBlock_, 'dragStop', + this.draggingBlock_.getDescendants(false), null); + Blockly.Events.fire(event); +}; + /** * Fire a move event at the end of a block drag. * @private From ce4163c7e4dfae39647499c1130743f9f9e443d1 Mon Sep 17 00:00:00 2001 From: Navil Perez Date: Thu, 17 Oct 2019 15:13:26 -0700 Subject: [PATCH 2/3] Fix capitalization in the docstring. --- core/block_dragger.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/block_dragger.js b/core/block_dragger.js index 2fb096c1d..6e6857506 100644 --- a/core/block_dragger.js +++ b/core/block_dragger.js @@ -189,7 +189,7 @@ Blockly.BlockDragger.prototype.startBlockDrag = function(currentDragDeltaXY, }; /** - * Fire a ui event at the start of a block drag. + * Fire a UI event at the start of a block drag. * @private */ Blockly.BlockDragger.prototype.fireDragStartEvent_ = function() { @@ -266,7 +266,7 @@ Blockly.BlockDragger.prototype.endBlockDrag = function(e, currentDragDeltaXY) { }; /** - * Fire a ui event at the end of a block drag. + * Fire a UI event at the end of a block drag. * @private */ Blockly.BlockDragger.prototype.fireDragEndEvent_ = function() { From c0784a61e7212bbbc394dcf14dc3b9f9a6aacb17 Mon Sep 17 00:00:00 2001 From: Navil Perez Date: Thu, 17 Oct 2019 15:23:10 -0700 Subject: [PATCH 3/3] Linting Fix --- core/block_dragger.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/block_dragger.js b/core/block_dragger.js index 6e6857506..9b6110f6b 100644 --- a/core/block_dragger.js +++ b/core/block_dragger.js @@ -195,7 +195,7 @@ Blockly.BlockDragger.prototype.startBlockDrag = function(currentDragDeltaXY, Blockly.BlockDragger.prototype.fireDragStartEvent_ = function() { var event = new Blockly.Events.Ui(this.draggingBlock_, 'dragStart', null, this.draggingBlock_.getDescendants(false)); - Blockly.Events.fire(event) + Blockly.Events.fire(event); }; /**