diff --git a/core/blockly.js b/core/blockly.js index 029f83d2e..c01e94a25 100644 --- a/core/blockly.js +++ b/core/blockly.js @@ -106,9 +106,9 @@ Blockly.clipboardSource_ = null; /** * Is the mouse dragging a block? - * 0 - No drag operation. - * 1 - Still inside the sticky DRAG_RADIUS. - * 2 - Freely draggable. + * DRAG_NONE - No drag operation. + * DRAG_STICKY - Still inside the sticky DRAG_RADIUS. + * DRAG_FREE - Freely draggable. * @private */ Blockly.dragMode_ = Blockly.DRAG_NONE; @@ -190,7 +190,7 @@ Blockly.svgResize = function(workspace) { Blockly.onMouseUp_ = function(e) { var workspace = Blockly.getMainWorkspace(); Blockly.Css.setCursor(Blockly.Css.Cursor.OPEN); - workspace.isScrolling = false; + workspace.dragMode_ = Blockly.DRAG_NONE; // Unbind the touch event if it exists. if (Blockly.onTouchUpWrapper_) { Blockly.unbindEvent_(Blockly.onTouchUpWrapper_); @@ -212,7 +212,7 @@ Blockly.onMouseMove_ = function(e) { return; // Multi-touch gestures won't have e.clientX. } var workspace = Blockly.getMainWorkspace(); - if (workspace.isScrolling) { + if (workspace.dragMode_ != Blockly.DRAG_NONE) { var dx = e.clientX - workspace.startDragMouseX; var dy = e.clientY - workspace.startDragMouseY; var metrics = workspace.startDragMetrics; @@ -231,6 +231,7 @@ Blockly.onMouseMove_ = function(e) { // Cancel the long-press if the drag has moved too far. if (Math.sqrt(dx * dx + dy * dy) > Blockly.DRAG_RADIUS) { Blockly.longStop_(); + workspace.dragMode_ = Blockly.DRAG_FREE; } e.stopPropagation(); e.preventDefault(); diff --git a/core/constants.js b/core/constants.js index f082905d5..0f327e2d9 100644 --- a/core/constants.js +++ b/core/constants.js @@ -154,7 +154,14 @@ Blockly.DRAG_NONE = 0; Blockly.DRAG_STICKY = 1; /** - * ENUM for freely draggable. + * ENUM for inside the non-sticky DRAG_RADIUS, for differentiating between + * clicks and drags. + * @const + */ +Blockly.DRAG_BEGIN = 1; + +/** + * ENUM for freely draggable (outside the DRAG_RADIUS, if one applies). * @const */ Blockly.DRAG_FREE = 2; diff --git a/core/flyout.js b/core/flyout.js index 94434ea2e..0647b7219 100644 --- a/core/flyout.js +++ b/core/flyout.js @@ -151,9 +151,9 @@ Blockly.Flyout.prototype.height_ = 0; /** * Is the flyout dragging (scrolling)? - * 0 - DRAG_NONE - no drag is ongoing or state is undetermined. - * 1 - DRAG_STICKY - still within the sticky drag radius. - * 2 - DRAG_FREE - in scroll mode (never create a new block). + * DRAG_NONE - no drag is ongoing or state is undetermined. + * DRAG_STICKY - still within the sticky drag radius. + * DRAG_FREE - in scroll mode (never create a new block). * @private */ Blockly.Flyout.prototype.dragMode_ = Blockly.DRAG_NONE; diff --git a/core/workspace_svg.js b/core/workspace_svg.js index 9d4cab477..b61c43742 100644 --- a/core/workspace_svg.js +++ b/core/workspace_svg.js @@ -84,9 +84,12 @@ Blockly.WorkspaceSvg.prototype.isFlyout = false; /** * Is this workspace currently being dragged around? - * @type {boolean} + * DRAG_NONE - No drag operation. + * DRAG_BEGIN - Still inside the initial DRAG_RADIUS. + * DRAG_FREE - Workspace has been dragged further than DRAG_RADIUS. + * @private */ -Blockly.WorkspaceSvg.prototype.isScrolling = false; +Blockly.WorkspaceSvg.prototype.dragMode_ = Blockly.DRAG_NONE; /** * Current horizontal scrolling offset. @@ -656,7 +659,7 @@ Blockly.WorkspaceSvg.prototype.onMouseDown_ = function(e) { // Right-click. this.showContextMenu_(e); } else if (this.scrollbar) { - this.isScrolling = true; + this.dragMode_ = Blockly.DRAG_BEGIN; // Record the current mouse position. this.startDragMouseX = e.clientX; this.startDragMouseY = e.clientY; @@ -716,7 +719,8 @@ Blockly.WorkspaceSvg.prototype.moveDrag = function(e) { * @return {boolean} True if currently dragging or scrolling. */ Blockly.WorkspaceSvg.prototype.isDragging = function() { - return Blockly.dragMode_ == Blockly.DRAG_FREE || this.isScrolling; + return Blockly.dragMode_ == Blockly.DRAG_FREE || + this.dragMode_ == Blockly.DRAG_FREE; }; /**