Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions packages/blockly/core/dragging/block_drag_strategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -902,7 +902,11 @@ export class BlockDragStrategy implements IDragStrategy {
blockAnimation.disconnectUiStop();
this.connectionPreviewer?.hidePreview();

if (!this.block.isDeadOrDying() && this.dragging) {
if (
!this.block.isDeadOrDying() &&
this.dragging &&
disposition !== DragDisposition.DELETE
) {
// These are expensive and don't need to be done if we're deleting, or
// if we've already stopped dragging because we moved back to the start.
this.workspace
Expand All @@ -921,7 +925,7 @@ export class BlockDragStrategy implements IDragStrategy {
this.redisableAllDraggedBlocks(this.block);
}

if (this.connectionCandidate) {
if (this.connectionCandidate && disposition !== DragDisposition.DELETE) {
// Applying connections also rerenders the relevant blocks.
this.applyConnections(this.connectionCandidate);
this.disposeStep();
Expand Down
46 changes: 46 additions & 0 deletions packages/blockly/tests/browser/test/dragger_test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -372,4 +372,50 @@ suite('Dragging into a delete area', function () {
});
});
});

test('does not delete blocks already on the workspace within the connection radius of a dragged block dropped on a delete area', async function () {
const {blockHasDeleteStyle, blockIsDeadOrDying, existingBlockDeleted} =
await this.browser.execute(() => {
const workspace = Blockly.getMainWorkspace();

const existingBlock = workspace.newBlock('controls_repeat');
existingBlock.initSvg();
existingBlock.render();

const draggingBlock = workspace.newBlock('controls_if');
draggingBlock.initSvg();
draggingBlock.render();

const deleteRect = workspace.trashcan.getClientRect();
const deleteRectCenter = rectCenterClient(deleteRect);

// Move the existing block near the trash so that the dragged block will
// attempt to connect on top of it.
existingBlock.moveTo(
new Blockly.utils.Coordinate(
deleteRectCenter.x - workspace.toolbox.getClientRect().right - 30,
deleteRectCenter.y + existingBlock.height / 2,
),
);

const state = getAssertionState(
draggingBlock,
deleteRectCenter,
deleteRect,
);

return {
...state,
existingBlockDeleted: existingBlock.isDeadOrDying(),
};
});

chai.assert.isFalse(
existingBlockDeleted,
'Expected existing block to not be deleted',
);

chai.assert.isTrue(blockHasDeleteStyle);
chai.assert.isTrue(blockIsDeadOrDying);
});
});