Selection Rectangle Bulk Delete Implementation #3873
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description:
This pull request introduces a new feature that allows users to bulk delete non-connected blocks by dragging a selection rectangle around them. This feature was integrated into activity.js and includes several new functions to handle user interactions with the canvas, such as mouse down, move, and up events, along with keypress detection for deletions.
Functions Added:
initializeSelectionEvents(): Sets up the event listeners for the canvas.
mouseDownHandler(event), mouseMoveHandler(event), mouseUpHandler(event): Handlers for mouse events to manage selection rectangle.
keyDownHandler(event): Detects the 'Delete' key to trigger the deletion of selected blocks.
updateCanvas(): Redraws the canvas, refreshing the display after block deletion.
drawSelectionRectangle(context): Draws the selection rectangle during the selection process.
findBlocksInSelection(): Identifies blocks within the selection rectangle, returning an array of block IDs. It calculates the selection bounds and checks each block's bounds to determine if it falls within the selection area.
deleteSelectedBlocks(): Deletes all blocks that have been selected. It iterates through the list of selected block IDs and removes each one, updating the canvas afterwards.
getBlockBounds(blockId): Retrieves the bounding box of a block, providing its position and dimensions. This function is essential for determining whether a block is within the selection rectangle.
removeBlock(blockId): Removes a block from the system and ensures that all references are properly cleared. This includes removing the block's visual representation and calling
Known Issues:
Canvas Interaction Limitation: Due to current limitations in the canvas interaction implementation, the selection rectangle does not trigger block deletions as expected. This might have something to do with the initialization of activity.js.
Request for Assistance:
I am seeking feedback and assistance on the following specific issues:
Enhancing Canvas Interactivity: Guidance on improving the interactivity of the canvas to ensure that the selection rectangle can effectively trigger block deletions, primarily with the initialization of activity.js.