Skip to content

Commit

Permalink
Long-press for block menu
Browse files Browse the repository at this point in the history
  • Loading branch information
jivansh77 committed Jan 2, 2025
1 parent 24f48f1 commit 5d7b31b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
28 changes: 26 additions & 2 deletions js/activity.js
Original file line number Diff line number Diff line change
Expand Up @@ -508,13 +508,34 @@ class Activity {
let longPressTimer = null;
const LONG_PRESS_DURATION = 500;

// Function to check if coordinates are within any block
const isCoordinateOnBlock = (x, y) => {
if (!this.blocks || !this.blocks.blockList) return false;

return this.blocks.blockList.some(block => {
if (!block || !block.container || block.trash) return false;

const blockX = block.container.x + this.blocksContainer.x;
const blockY = block.container.y + this.blocksContainer.y;

return (x >= blockX &&
x <= blockX + block.width &&
y >= blockY &&
y <= blockY + block.height);
});
};

document.addEventListener("contextmenu", (event) => {
event.preventDefault();
event.stopPropagation();

const canvasRect = this.canvas.getBoundingClientRect();
const x = event.clientX - canvasRect.left;
const y = event.clientY - canvasRect.top;

if (!this.beginnerMode &&
event.target.id === "myCanvas" &&
!event.target.closest('.block')) {
!isCoordinateOnBlock(x, y)) {
this._displayHelpfulWheel(event);
}
}, false);
Expand All @@ -523,10 +544,13 @@ class Activity {
if (event.touches.length !== 1) return;

const touch = event.touches[0];
const canvasRect = this.canvas.getBoundingClientRect();
const x = touch.clientX - canvasRect.left;
const y = touch.clientY - canvasRect.top;

if (!this.beginnerMode &&
touch.target.id === "myCanvas" &&
!touch.target.closest('.block')) {
!isCoordinateOnBlock(x, y)) {

longPressTimer = setTimeout(() => {
const touchEvent = {
Expand Down
3 changes: 0 additions & 3 deletions js/blocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -5039,9 +5039,6 @@ class Blocks {
}

this.inLongPress = true;

const helpfulWheel = docById("helpfulWheelDiv");
helpfulWheel.style.display = "none";

piemenuBlockContext(this.blockList[this.activeBlock]);
};
Expand Down

0 comments on commit 5d7b31b

Please sign in to comment.