mirror of
https://github.com/google/blockly.git
synced 2026-01-06 00:20:37 +01:00
Preventing workspace click when trashcan is clicked (#4497)
This commit is contained in:
@@ -313,9 +313,13 @@ Blockly.Trashcan.prototype.createDom = function() {
|
||||
this.svgLid_.setAttributeNS(Blockly.utils.dom.XLINK_NS, 'xlink:href',
|
||||
this.workspace_.options.pathToMedia + Blockly.SPRITE.url);
|
||||
|
||||
Blockly.bindEventWithChecks_(this.svgGroup_, 'mouseup', this, this.click);
|
||||
// bindEventWithChecks_ quashes events too aggressively. See:
|
||||
// https://groups.google.com/forum/#!topic/blockly/QF4yB9Wx00s
|
||||
// Using bindEventWithChecks_ for blocking mousedown causes issue in mobile.
|
||||
// See #4303
|
||||
Blockly.bindEvent_(
|
||||
this.svgGroup_, 'mousedown', this, this.blockMouseDownWhenOpenable_);
|
||||
Blockly.bindEvent_(this.svgGroup_, 'mouseup', this, this.click);
|
||||
// Bind to body instead of this.svgGroup_ so that we don't get lid jitters
|
||||
Blockly.bindEvent_(body, 'mouseover', this, this.mouseOver_);
|
||||
Blockly.bindEvent_(body, 'mouseout', this, this.mouseOut_);
|
||||
@@ -566,6 +570,17 @@ Blockly.Trashcan.prototype.fireUiEvent_ = function(trashcanOpen) {
|
||||
Blockly.Events.fire(uiEvent);
|
||||
};
|
||||
|
||||
/**
|
||||
* Prevents a workspace scroll and click event if the trashcan has blocks.
|
||||
* @param {!Event} e A mouse down event.
|
||||
* @private
|
||||
*/
|
||||
Blockly.Trashcan.prototype.blockMouseDownWhenOpenable_ = function(e) {
|
||||
if (!this.contentsIsOpen() && this.hasContents_()) {
|
||||
e.stopPropagation(); // Don't start a workspace scroll.
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Indicate that the trashcan can be clicked (by opening it) if it has blocks.
|
||||
* @private
|
||||
|
||||
Reference in New Issue
Block a user