From 7e82d6f898f539249c0860d0d571ce81176702df Mon Sep 17 00:00:00 2001 From: jivansh77 Date: Mon, 6 Jan 2025 03:00:28 +0530 Subject: [PATCH] Move preventdafult --- js/piemenus.js | 39 +++++++++++++++++++++++---------------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/js/piemenus.js b/js/piemenus.js index f7510245ed..64e7d65133 100644 --- a/js/piemenus.js +++ b/js/piemenus.js @@ -3518,38 +3518,45 @@ const piemenuBlockContext = (block) => { // Long-press on blocks let longPressTimer = null; const LONG_PRESS_DURATION = 500; + let touchStarted = false; block.container.on("touchstart", (event) => { - event.preventDefault(); + // event.preventDefault(); event.stopPropagation(); if (event.touches.length !== 1) return; + touchStarted = true; + longPressTimer = setTimeout(() => { - docById("contextWheelDiv").style.position = "absolute"; - docById("contextWheelDiv").style.display = ""; - - const x = block.container.x; - const y = block.container.y; - const canvasLeft = block.activity.canvas.offsetLeft + 28 * block.blocks.blockScale; - const canvasTop = block.activity.canvas.offsetTop + 6 * block.blocks.blockScale; - - docById("contextWheelDiv").style.left = Math.round((x + block.activity.blocksContainer.x) * - block.activity.getStageScale() + canvasLeft) + "px"; - docById("contextWheelDiv").style.top = Math.round((y + block.activity.blocksContainer.y) * - block.activity.getStageScale() + canvasTop) + "px"; + if (touchStarted) { + event.preventDefault(); + + docById("contextWheelDiv").style.position = "absolute"; + docById("contextWheelDiv").style.display = ""; + + const x = block.container.x; + const y = block.container.y; + const canvasLeft = block.activity.canvas.offsetLeft + 28 * block.blocks.blockScale; + const canvasTop = block.activity.canvas.offsetTop + 6 * block.blocks.blockScale; + + docById("contextWheelDiv").style.left = Math.round((x + block.activity.blocksContainer.x) * + block.activity.getStageScale() + canvasLeft) - 150 + "px"; + docById("contextWheelDiv").style.top = Math.round((y + block.activity.blocksContainer.y) * + block.activity.getStageScale() + canvasTop) - 150 + "px"; + } }, LONG_PRESS_DURATION); - }); + }, { passive: false }); const clearTimer = () => { + touchStarted = false; if (longPressTimer) { clearTimeout(longPressTimer); longPressTimer = null; } }; - block.container.on("touchmove", (event) => { - event.preventDefault(); + block.container.on("touchmove", () => { clearTimer(); }); block.container.on("touchend", clearTimer);