@@ -140,6 +140,21 @@ Blockly.Flyout.prototype.height_ = 0;
140
140
*/
141
141
Blockly . Flyout . prototype . verticalOffset_ = 0 ;
142
142
143
+ /**
144
+ * Range of a drag angle from a fixed flyout considered "dragging toward workspace."
145
+ * Drags that are within the bounds of this many degrees from the orthogonal
146
+ * line to the flyout edge are considered to be "drags toward the workspace."
147
+ * Example:
148
+ * Flyout Edge Workspace
149
+ * [block] / <-within this angle, drags "toward workspace" |
150
+ * [block] ---- orthogonal to flyout boundary ---- |
151
+ * [block] \ |
152
+ * The angle is given in degrees from the orthogonal.
153
+ * @type {number }
154
+ * @private
155
+ */
156
+ Blockly . Flyout . prototype . dragAngleRange_ = 70 ;
157
+
143
158
/**
144
159
* Creates the flyout's DOM. Only needs to be called once.
145
160
* @return {!Element } The flyout's SVG group.
@@ -301,7 +316,7 @@ Blockly.Flyout.prototype.setMetrics_ = function(xyRatio) {
301
316
302
317
Blockly . Flyout . prototype . setVerticalOffset = function ( verticalOffset ) {
303
318
this . verticalOffset_ = verticalOffset ;
304
- }
319
+ } ;
305
320
306
321
/**
307
322
* Move the toolbox to the edge of the workspace.
@@ -671,6 +686,8 @@ Blockly.Flyout.prototype.blockMouseDown_ = function(block) {
671
686
// Left-click (or middle click)
672
687
Blockly . Css . setCursor ( Blockly . Css . Cursor . CLOSED ) ;
673
688
// Record the current mouse position.
689
+ flyout . startDragMouseY_ = e . clientY ;
690
+ flyout . startDragMouseX_ = e . clientX ;
674
691
Blockly . Flyout . startDownEvent_ = e ;
675
692
Blockly . Flyout . startBlock_ = block ;
676
693
Blockly . Flyout . startFlyout_ = flyout ;
@@ -751,12 +768,63 @@ Blockly.Flyout.prototype.onMouseMoveBlock_ = function(e) {
751
768
}
752
769
var dx = e . clientX - Blockly . Flyout . startDownEvent_ . clientX ;
753
770
var dy = e . clientY - Blockly . Flyout . startDownEvent_ . clientY ;
754
- // Still dragging within the sticky DRAG_RADIUS.
755
- if ( Math . sqrt ( dx * dx + dy * dy ) > Blockly . DRAG_RADIUS ) {
771
+
772
+ // Only create a block if the user is dragging toward the workspace,
773
+ // Otherwise the drag might be the start of a scroll in the flyout.
774
+ // Don't create a block within the sticky drag radius.
775
+ if ( this . isDragTowardWorkspace_ ( dx , dy ) &&
776
+ Math . sqrt ( dx * dx + dy * dy ) > Blockly . DRAG_RADIUS ) {
756
777
// Create the block.
757
778
Blockly . Flyout . startFlyout_ . createBlockFunc_ ( Blockly . Flyout . startBlock_ ) (
758
779
Blockly . Flyout . startDownEvent_ ) ;
780
+ } else {
781
+ // Do a scroll
782
+ Blockly . Flyout . startFlyout_ . onMouseMove_ ( e ) ;
783
+ }
784
+ e . stopPropagation ( ) ;
785
+ } ;
786
+
787
+ /**
788
+ * Determine if a drag delta is toward the workspace, based on the position
789
+ * and orientation of the flyout. This is used in onMouseMoveBlock_ to determine
790
+ * if a new block should be created or if the flyout should scroll.
791
+ * @param {number } dx X delta of the drag
792
+ * @param {number } dy Y delta of the drag
793
+ * @return {boolean } true if the drag is toward the workspace.
794
+ * @private
795
+ */
796
+ Blockly . Flyout . prototype . isDragTowardWorkspace_ = function ( dx , dy ) {
797
+ // Direction goes from -180 to 180, with 0 toward the right and 90 on top.
798
+ var dragDirection = Math . atan2 ( dy , dx ) / Math . PI * 180 ;
799
+
800
+ var draggingTowardWorkspace = false ;
801
+ var range = Blockly . Flyout . startFlyout_ . dragAngleRange_ ;
802
+ if ( Blockly . Flyout . startFlyout_ . horizontalLayout_ ) {
803
+ if ( Blockly . Flyout . startFlyout_ . toolboxPosition_ == Blockly . TOOLBOX_AT_TOP ) {
804
+ // Horizontal at top
805
+ if ( dragDirection < 90 + range && dragDirection > 90 - range ) {
806
+ draggingTowardWorkspace = true ;
807
+ }
808
+ } else {
809
+ // Horizontal at bottom
810
+ if ( dragDirection > - 90 - range && dragDirection < - 90 + range ) {
811
+ draggingTowardWorkspace = true ;
812
+ }
813
+ }
814
+ } else {
815
+ if ( Blockly . Flyout . startFlyout_ . toolboxPosition_ == Blockly . TOOLBOX_AT_LEFT ) {
816
+ // Vertical at left
817
+ if ( dragDirection < range && dragDirection > - range ) {
818
+ draggingTowardWorkspace = true ;
819
+ }
820
+ } else {
821
+ // Vertical at right
822
+ if ( dragDirection < - 180 + range || dragDirection > 180 - range ) {
823
+ draggingTowardWorkspace = true ;
824
+ }
825
+ }
759
826
}
827
+ return draggingTowardWorkspace ;
760
828
} ;
761
829
762
830
/**
0 commit comments