From 94821801f57da48d8a3f5df3c4c7a44dece97244 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Wed, 19 Aug 2026 09:58:40 -0700 Subject: [PATCH] fix: Make reverting block drags from the flyout delete the dragged block --- packages/blockly/core/dragging/dragger.ts | 16 +++++++++++++++- .../tests/mocha/keyboard_movement_test.js | 17 +++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/packages/blockly/core/dragging/dragger.ts b/packages/blockly/core/dragging/dragger.ts index 99280a7c93e..4be1952edc8 100644 --- a/packages/blockly/core/dragging/dragger.ts +++ b/packages/blockly/core/dragging/dragger.ts @@ -4,6 +4,7 @@ * SPDX-License-Identifier: Apache-2.0 */ +import {BlockSvg} from '../block_svg.js'; import {ComponentManager} from '../component_manager.js'; import * as eventUtils from '../events/utils.js'; import {getFocusManager} from '../focus_manager.js'; @@ -22,7 +23,14 @@ export class Dragger implements IDragger { protected dragTarget: IDragTarget | null = null; + protected revertShouldDelete = false; + constructor(protected draggable: IDraggable) { + // Blocks originating from the flyout should be deleted if the drag is + // reverted. + if (draggable instanceof BlockSvg && draggable.workspace.isFlyout) { + this.revertShouldDelete = true; + } this.startLoc = draggable.getRelativeToSurfaceXY(); } @@ -167,7 +175,13 @@ export class Dragger implements IDragger { } /** Handles a drag being reverted. */ - onDragRevert() { + onDragRevert(e?: PointerEvent | KeyboardEvent) { + if (this.revertShouldDelete && isDeletable(this.draggable)) { + this.draggable.endDrag(e, DragDisposition.DELETE); + this.draggable.dispose(); + return; + } + this.draggable.revertDrag(); if (isFocusableNode(this.draggable)) { getFocusManager().focusNode(this.draggable); diff --git a/packages/blockly/tests/mocha/keyboard_movement_test.js b/packages/blockly/tests/mocha/keyboard_movement_test.js index 7e514d9e2f7..ca488ad03cd 100644 --- a/packages/blockly/tests/mocha/keyboard_movement_test.js +++ b/packages/blockly/tests/mocha/keyboard_movement_test.js @@ -547,6 +547,23 @@ suite('Keyboard-driven movement', function () { this.modifiers = [Blockly.utils.KeyCodes.CTRL_CMD]; }); + test('deletes blocks dragged from the flyout when a drag is reverted', function () { + // One block is on the workspace to start. + let blocks = this.workspace.getTopBlocks(); + assert.equal(blocks.length, 1); + + // Starting a move from the toolbox creates a new block on the main workspace. + focusToolbox(this.workspace); + startMove(this.workspace); + blocks = this.workspace.getTopBlocks(); + assert.equal(blocks.length, 2); + + // Canceling the move originating from the toolbox deletes the new block. + cancelMove(this.workspace); + blocks = this.workspace.getTopBlocks(); + assert.equal(blocks.length, 1); + }); + suite('in unconstrained mode', function () { testMovingUp(); testMovingDown();