Preventing workspace click when trashcan is clicked (#4497)

This commit is contained in:
Monica Kozbial
2020-12-07 10:38:04 -08:00
committed by GitHub
parent 53cf889069
commit dd977b295b

View File

@@ -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