Skip to content

Commit

Permalink
fix: prevent helpfulWheel from appearing on block right-click (#4219)
Browse files Browse the repository at this point in the history
* fix: prevent helpfulWheel from appearing on block right-click

* fix:created a general utility function to detect block clicks, updated the right click detection on blocks

* removed trailing spaces
  • Loading branch information
BeNikk authored Jan 4, 2025
1 parent 009b300 commit 340a1d0
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
10 changes: 5 additions & 5 deletions js/activity.js
Original file line number Diff line number Diff line change
Expand Up @@ -510,11 +510,11 @@ class Activity {
(event) => {
event.preventDefault();
event.stopPropagation();
if (!this.beginnerMode) {
if (event.target.id === "myCanvas") {
this._displayHelpfulWheel(event);
}
}
if (this.beginnerMode) return;
if (!this.blocks.isCoordinateOnBlock(event.clientX, event.clientY) &&
event.target.id === "myCanvas") {
this._displayHelpfulWheel(event);
}
},
false
);
Expand Down
20 changes: 20 additions & 0 deletions js/blocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -7036,5 +7036,25 @@ class Blocks {
this.setSelectedBlocks = (blocks) => {
this.selectedBlocks = blocks;
};

/**
* Checks if coordinates intersect with any block
* @public
* @param {number} x - The x coordinate to check
* @param {number} y - The y coordinate to check
* @returns {boolean} True if coordinates intersect with a block
*/
this.isCoordinateOnBlock = function(x, y) {
return this.blockList.some(block => {
if (block.trash) return false;

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

0 comments on commit 340a1d0

Please sign in to comment.