From 52eb6adcc23d1ad376cd87cc9c1c27886087fcf4 Mon Sep 17 00:00:00 2001 From: Neil Fraser Date: Wed, 20 Apr 2016 05:03:05 -0700 Subject: [PATCH] Add click events to non-closing flyout blocks. Issue #337. --- core/flyout.js | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/core/flyout.js b/core/flyout.js index f960bafba..d4930be8b 100644 --- a/core/flyout.js +++ b/core/flyout.js @@ -28,6 +28,7 @@ goog.provide('Blockly.Flyout'); goog.require('Blockly.Block'); goog.require('Blockly.Comment'); +goog.require('Blockly.Events.Ui'); goog.require('Blockly.WorkspaceSvg'); goog.require('goog.dom'); goog.require('goog.events'); @@ -436,16 +437,18 @@ Blockly.Flyout.prototype.show = function(xmlList) { if (this.autoClose) { this.listeners_.push(Blockly.bindEvent_(root, 'mousedown', null, this.createBlockFunc_(block))); + this.listeners_.push(Blockly.bindEvent_(rect, 'mousedown', null, + this.createBlockFunc_(block))); } else { this.listeners_.push(Blockly.bindEvent_(root, 'mousedown', null, this.blockMouseDown_(block))); + this.listeners_.push(Blockly.bindEvent_(rect, 'mousedown', null, + this.blockMouseDown_(block))); } this.listeners_.push(Blockly.bindEvent_(root, 'mouseover', block, block.addSelect)); this.listeners_.push(Blockly.bindEvent_(root, 'mouseout', block, block.removeSelect)); - this.listeners_.push(Blockly.bindEvent_(rect, 'mousedown', null, - this.createBlockFunc_(block))); this.listeners_.push(Blockly.bindEvent_(rect, 'mouseover', block, block.addSelect)); this.listeners_.push(Blockly.bindEvent_(rect, 'mouseout', block, @@ -544,7 +547,7 @@ Blockly.Flyout.prototype.blockMouseDown_ = function(block) { Blockly.Flyout.startBlock_ = block; Blockly.Flyout.startFlyout_ = flyout; Blockly.Flyout.onMouseUpWrapper_ = Blockly.bindEvent_(document, - 'mouseup', this, Blockly.terminateDrag_); + 'mouseup', this, flyout.onMouseUp_); Blockly.Flyout.onMouseMoveBlockWrapper_ = Blockly.bindEvent_(document, 'mousemove', this, flyout.onMouseMoveBlock_); } @@ -574,6 +577,23 @@ Blockly.Flyout.prototype.onMouseDown_ = function(e) { e.stopPropagation(); }; +/** + * Handle a mouse-up anywhere in the SVG pane. Is only registered when a + * block is clicked. We can't use mouseUp on the block since a fast-moving + * cursor can briefly escape the block before it catches up. + * @param {!Event} e Mouse up event. + * @private + */ +Blockly.Flyout.prototype.onMouseUp_ = function(e) { + if (Blockly.dragMode_ != Blockly.DRAG_FREE && + !Blockly.WidgetDiv.isVisible()) { + Blockly.Events.fire( + new Blockly.Events.Ui(Blockly.Flyout.startBlock_, 'click', + undefined, undefined)); + } + Blockly.terminateDrag_(); +}; + /** * Handle a mouse-move to vertically drag the flyout. * @param {!Event} e Mouse move event.