Tweaks for clicking blocks in toolbox (#681)

* Make a copy of listeners (fix #680), allow ID lookup in flyout

* Move flyout cursor change to when block drags

* Fire a stack-click event in flyout, to match workspace
This commit is contained in:
Tim Mickel 2016-10-13 17:09:41 -04:00 committed by GitHub
parent 2d48a260ed
commit f318d6a7ea
2 changed files with 12 additions and 3 deletions

View file

@ -584,7 +584,6 @@ Blockly.Flyout.prototype.blockMouseDown_ = function(block) {
Blockly.DropDownDiv.hideWithoutAnimation();
Blockly.hideChaff();
// Left-click (or middle click)
Blockly.Css.setCursor(Blockly.Css.Cursor.CLOSED);
// Record the current mouse position.
flyout.startDragMouseY_ = e.clientY;
flyout.startDragMouseX_ = e.clientX;
@ -648,6 +647,9 @@ Blockly.Flyout.prototype.onMouseUp_ = function(/*e*/) {
Blockly.Events.fire(
new Blockly.Events.Ui(Blockly.Flyout.startBlock_, 'click',
undefined, undefined));
Blockly.Events.fire(
new Blockly.Events.Ui(Blockly.Flyout.startBlock_, 'stackclick',
undefined, undefined));
}
}
Blockly.terminateDrag_();
@ -699,6 +701,7 @@ Blockly.Flyout.prototype.onMouseMoveBlock_ = function(e) {
e.stopPropagation();
return;
}
Blockly.Css.setCursor(Blockly.Css.Cursor.CLOSED);
var dx = e.clientX - Blockly.Flyout.startDownEvent_.clientX;
var dy = e.clientY - Blockly.Flyout.startDownEvent_.clientY;
var createBlock = this.determineDragIntention_(dx, dy);

View file

@ -462,7 +462,9 @@ Blockly.Workspace.prototype.fireChangeListener = function(event) {
this.undoStack_.unshift();
}
}
for (var i = 0, func; func = this.listeners_[i]; i++) {
// Copy listeners in case a listener attaches/detaches itself.
var currentListeners = this.listeners_.slice();
for (var i = 0, func; func = currentListeners[i]; i++) {
func(event);
}
};
@ -473,7 +475,11 @@ Blockly.Workspace.prototype.fireChangeListener = function(event) {
* @return {Blockly.Block} The sought after block or null if not found.
*/
Blockly.Workspace.prototype.getBlockById = function(id) {
return this.blockDB_[id] || null;
var block = this.blockDB_[id];
if (!block && this.getFlyout() && this.getFlyout().getWorkspace()) {
block = this.getFlyout().getWorkspace().blockDB_[id];
}
return block || null;
};
/**