More comprehensive approach to gesture detection.

Search all workspaces.  The flaw with looking at the workspace of the selected block is that dragging a workspace is a gesture but has no selected block.
This commit is contained in:
Neil Fraser
2019-03-29 11:24:10 -07:00
committed by Neil Fraser
parent e9de083361
commit 51bfa9455d
3 changed files with 17 additions and 6 deletions

View File

@@ -960,10 +960,9 @@ Blockly.Gesture.prototype.getInsertionMarkers = function() {
* @return {boolean} True if gesture is occurring.
*/
Blockly.Gesture.inProgress = function() {
// If a drag is occurring, then it involves a selected block on a workspace.
if (Blockly.selected) {
var currentWorkspace = Blockly.selected.workspace;
if (currentWorkspace && currentWorkspace.currentGesture_) {
var workspaces = Blockly.Workspace.getAll();
for (var i = 0, workspace; workspace = workspaces[i]; i++) {
if (workspace.currentGesture_) {
return true;
}
}

View File

@@ -421,8 +421,8 @@ Blockly.init_ = function(mainWorkspace) {
Blockly.inject.bindDocumentEvents_ = function() {
if (!Blockly.documentEventsBound_) {
Blockly.bindEventWithChecks_(document, 'scroll', null, function() {
for (var workspaceId in Blockly.Workspace.WorkspaceDB_) {
var workspace = Blockly.Workspace.WorkspaceDB_[workspaceId];
var workspaces = Blockly.Workspace.getAll();
for (var i = 0, workspace; workspace = workspaces[i]; i++) {
if (workspace.updateInverseScreenCTM) {
workspace.updateInverseScreenCTM();
}

View File

@@ -734,6 +734,18 @@ Blockly.Workspace.getById = function(id) {
return Blockly.Workspace.WorkspaceDB_[id] || null;
};
/**
* Find all workspaces.
* @return {!Array.<!Blockly.Workspace>} Array of workspaces.
*/
Blockly.Workspace.getAll = function() {
var workspaces = [];
for (var workspaceId in Blockly.Workspace.WorkspaceDB_) {
workspaces.push(Blockly.Workspace.WorkspaceDB_[workspaceId]);
}
return workspaces;
};
// Export symbols that would otherwise be renamed by Closure compiler.
Blockly.Workspace.prototype['clear'] = Blockly.Workspace.prototype.clear;
Blockly.Workspace.prototype['clearUndo'] =