From 2774cc16630a0d17bfcba6dfdd0d033c309e1379 Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Wed, 31 Aug 2016 18:04:27 -0700 Subject: [PATCH] Fix longpress in flyout; leave debug messages in --- core/block_svg.js | 10 ++++++++++ core/flyout.js | 19 +++++++++++++------ core/inject.js | 11 ++++++----- core/scrollbar.js | 1 + core/utils.js | 3 ++- 5 files changed, 32 insertions(+), 12 deletions(-) diff --git a/core/block_svg.js b/core/block_svg.js index 9d0955279..42520184a 100644 --- a/core/block_svg.js +++ b/core/block_svg.js @@ -531,6 +531,16 @@ Blockly.BlockSvg.prototype.onMouseDown_ = function(e) { return; } if (this.isInFlyout) { + // longStart's simulation of right-clicks for longpresses on touch devices + // calls the object's onMouseDown, so its code path passes through here only + // on touch. + // definitely want to show the context menu, clear touch identifier, etc. + // what about hideChaff, select, and so on? + if (e.type == 'touchstart' && Blockly.isRightButton(e)) { + Blockly.Flyout.blockRightClick_(e, this); + e.stopPropagation(); + e.preventDefault(); + } return; } if (this.isInMutator) { diff --git a/core/flyout.js b/core/flyout.js index 0c305e9cf..27a5a754e 100644 --- a/core/flyout.js +++ b/core/flyout.js @@ -844,6 +844,13 @@ Blockly.Flyout.prototype.addBlockListeners_ = function(root, block, rect) { block.removeSelect)); }; +Blockly.Flyout.blockRightClick_ = function(e, block) { + Blockly.terminateDrag_(); + Blockly.hideChaff(true); + block.showContextMenu_(e); + Blockly.clearTouchIdentifier(); +}; + /** * Handle a mouse-down on an SVG block in a non-closing flyout. * @param {!Blockly.Block} block The flyout block to copy. @@ -853,13 +860,11 @@ Blockly.Flyout.prototype.addBlockListeners_ = function(root, block, rect) { Blockly.Flyout.prototype.blockMouseDown_ = function(block) { var flyout = this; return function(e) { - Blockly.terminateDrag_(); - Blockly.hideChaff(true); if (Blockly.isRightButton(e)) { - // Right-click. - block.showContextMenu_(e); - Blockly.clearTouchIdentifier(); + Blockly.Flyout.blockRightClick_(e, block); } else { + Blockly.terminateDrag_(); + Blockly.hideChaff(true); // Left-click (or middle click) Blockly.Css.setCursor(Blockly.Css.Cursor.CLOSED); // Record the current mouse position. @@ -911,8 +916,8 @@ Blockly.Flyout.prototype.onMouseDown_ = function(e) { * @private */ Blockly.Flyout.prototype.onMouseUp_ = function(e) { - Blockly.clearTouchIdentifier(); if (!this.workspace_.isDragging()) { + Blockly.clearTouchIdentifier(); if (this.autoClose) { this.createBlockFunc_(Blockly.Flyout.startBlock_)( Blockly.Flyout.startDownEvent_); @@ -976,9 +981,11 @@ Blockly.Flyout.prototype.onMouseMoveBlock_ = function(e) { var createBlock = this.determineDragIntention_(dx, dy); if (createBlock) { + Blockly.longStop_(); this.createBlockFunc_(Blockly.Flyout.startBlock_)( Blockly.Flyout.startDownEvent_); } else if (this.dragMode_ == Blockly.DRAG_FREE) { + Blockly.longStop_(); // Do a scroll. this.onMouseMove_(e); } diff --git a/core/inject.js b/core/inject.js index 3aa035467..4c0ff3d3d 100644 --- a/core/inject.js +++ b/core/inject.js @@ -359,13 +359,14 @@ Blockly.inject.loadSounds_ = function(pathToMedia, workspace) { while (soundBinds.length) { Blockly.unbindEvent_(soundBinds.pop()); } - // These are bound on mouse/touch events with Blockly.bindEvent_, so they - // restrict the touch identifier that will be recognized. But this is - // really something that happens on a click, not a drag, so that's not - // necessary. - //Blockly.clearTouchIdentifier(); workspace.preloadAudio_(); }; + + // These are bound on mouse/touch events with Blockly.bindEvent_, so they + // restrict the touch identifier that will be recognized. But this is + // really something that happens on a click, not a drag, so that's not + // necessary. + // Android ignores any sound not loaded as a result of a user action. soundBinds.push( Blockly.bindEvent_(document, 'mousemove', null, unbindSounds, true)); diff --git a/core/scrollbar.js b/core/scrollbar.js index f1c28b161..cc9318624 100644 --- a/core/scrollbar.js +++ b/core/scrollbar.js @@ -599,6 +599,7 @@ Blockly.Scrollbar.prototype.setVisible = function(visible) { * @private */ Blockly.Scrollbar.prototype.onMouseDownBar_ = function(e) { + Blockly.clearTouchIdentifier(); // This is really a click. this.cleanUp_(); if (Blockly.isRightButton(e)) { // Right-click. diff --git a/core/utils.js b/core/utils.js index 39fbe56c8..045566057 100644 --- a/core/utils.js +++ b/core/utils.js @@ -101,7 +101,7 @@ Blockly.hasClass_ = function(element, className) { Blockly.bindEvent_ = function(node, name, thisObject, func, opt_noCaptureIdentifier) { var wrapFunc = function(e) { - var captureIdentifier = opt_noCaptureIdentifier || true; + var captureIdentifier = !opt_noCaptureIdentifier; // Handle each touch point separately. If the event was a mouse event, this // will hand back an array with one element, which we're fine handling. var events = Blockly.bindEvent_.splitEventByTouches(e); @@ -175,6 +175,7 @@ Blockly.isMouseOrTouchEvent = function(e) { }; /** + * TODO (rachel-fenichel): consider moving all of this to touch.js * Split an event into an array of events, one per changed touch or mouse * point. * @param {!Event} e A mouse event or a touch event with one or more changed