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
16 changes: 15 additions & 1 deletion packages/blockly/core/dragging/dragger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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();
}

Expand Down Expand Up @@ -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);
Expand Down
17 changes: 17 additions & 0 deletions packages/blockly/tests/mocha/keyboard_movement_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Loading