From d3f813f3ff1c2eb85003e9f999f928bd845af710 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Fri, 10 Apr 2026 13:36:08 -0700 Subject: [PATCH] fix: Fix bug that caused blocks inserted via Enter to not attach --- 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 cf6952a858b..eb3b9fbb026 100644 --- a/packages/blockly/core/block_svg.ts +++ b/packages/blockly/core/block_svg.ts @@ -1911,9 +1911,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 37dd08bc44a..affbf61b234 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 5e3cea346bf..2cbc1a35363 100644 --- a/packages/blockly/core/shortcut_items.ts +++ b/packages/blockly/core/shortcut_items.ts @@ -859,7 +859,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 f9c7fe3f54a..6efa50a3c34 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(); });