From 0c4ec192baa6f9b06834fac0f4ddcadcdfcce4e8 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Wed, 15 Apr 2026 08:29:43 -0700 Subject: [PATCH] fix: Fix bug that caused blocks inserted via Enter to not attach (#9699) --- packages/blockly/core/block_svg.ts | 4 ++-- packages/blockly/core/interfaces/i_focusable_node.ts | 4 +++- packages/blockly/core/shortcut_items.ts | 2 +- packages/blockly/tests/mocha/shortcut_items_test.js | 10 ++++++++++ 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/packages/blockly/core/block_svg.ts b/packages/blockly/core/block_svg.ts index 43f47faa6..8a682ab39 100644 --- a/packages/blockly/core/block_svg.ts +++ b/packages/blockly/core/block_svg.ts @@ -1918,9 +1918,9 @@ export class BlockSvg * main workspace. If this block has a single full-block field, that field * will be focused. Otherwise, this is a no-op. */ - performAction() { + performAction(e?: KeyboardEvent) { if (this.workspace.isFlyout) { - KeyboardMover.mover.startMove(this); + KeyboardMover.mover.startMove(this, e); return; } else if (this.isSimpleReporter()) { for (const input of this.inputList) { diff --git a/packages/blockly/core/interfaces/i_focusable_node.ts b/packages/blockly/core/interfaces/i_focusable_node.ts index 37dd08bc4..affbf61b2 100644 --- a/packages/blockly/core/interfaces/i_focusable_node.ts +++ b/packages/blockly/core/interfaces/i_focusable_node.ts @@ -104,8 +104,10 @@ export interface IFocusableNode { * Optional method invoked when this node has focus and the user acts on it by * pressing Enter or Space. Behavior should generally be similar to the node * being clicked on. + * + * @param e The event that triggered this action, if any. */ - performAction?(): void; + performAction?(e?: Event): void; } /** diff --git a/packages/blockly/core/shortcut_items.ts b/packages/blockly/core/shortcut_items.ts index 0c594d0f9..14ebd3e20 100644 --- a/packages/blockly/core/shortcut_items.ts +++ b/packages/blockly/core/shortcut_items.ts @@ -861,7 +861,7 @@ export function registerPerformAction() { const focusedNode = getFocusManager().getFocusedNode(); if (focusedNode && 'performAction' in focusedNode) { e.preventDefault(); - focusedNode.performAction?.(); + focusedNode.performAction?.(e); return true; } return false; diff --git a/packages/blockly/tests/mocha/shortcut_items_test.js b/packages/blockly/tests/mocha/shortcut_items_test.js index 8df3e662f..67e0d2593 100644 --- a/packages/blockly/tests/mocha/shortcut_items_test.js +++ b/packages/blockly/tests/mocha/shortcut_items_test.js @@ -1037,6 +1037,10 @@ suite('Keyboard Shortcut Items', function () { }); test('Inserts blocks from the flyout in move mode', function () { + const first = this.workspace.newBlock('stack_block'); + first.initSvg(); + first.render(); + this.workspace.getToolbox().selectItemByPosition(0); const block = this.workspace .getNavigator() @@ -1053,6 +1057,12 @@ suite('Keyboard Shortcut Items', function () { assert.isTrue(movingBlock.isDragging()); assert.isFalse(movingBlock.workspace.isFlyout); + const hasInsertionMarker = this.workspace + .getTopBlocks() + .flatMap((b) => b.getChildren()) + .some((b) => b.isInsertionMarker()); + assert.isTrue(hasInsertionMarker); + Blockly.KeyboardMover.mover.abortMove(); });