Skip to content

Commit 0c4ec19

Browse files
authored
fix: Fix bug that caused blocks inserted via Enter to not attach (#9699)
1 parent 91d02ee commit 0c4ec19

4 files changed

Lines changed: 16 additions & 4 deletions

File tree

packages/blockly/core/block_svg.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1918,9 +1918,9 @@ export class BlockSvg
19181918
* main workspace. If this block has a single full-block field, that field
19191919
* will be focused. Otherwise, this is a no-op.
19201920
*/
1921-
performAction() {
1921+
performAction(e?: KeyboardEvent) {
19221922
if (this.workspace.isFlyout) {
1923-
KeyboardMover.mover.startMove(this);
1923+
KeyboardMover.mover.startMove(this, e);
19241924
return;
19251925
} else if (this.isSimpleReporter()) {
19261926
for (const input of this.inputList) {

packages/blockly/core/interfaces/i_focusable_node.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,10 @@ export interface IFocusableNode {
104104
* Optional method invoked when this node has focus and the user acts on it by
105105
* pressing Enter or Space. Behavior should generally be similar to the node
106106
* being clicked on.
107+
*
108+
* @param e The event that triggered this action, if any.
107109
*/
108-
performAction?(): void;
110+
performAction?(e?: Event): void;
109111
}
110112

111113
/**

packages/blockly/core/shortcut_items.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -861,7 +861,7 @@ export function registerPerformAction() {
861861
const focusedNode = getFocusManager().getFocusedNode();
862862
if (focusedNode && 'performAction' in focusedNode) {
863863
e.preventDefault();
864-
focusedNode.performAction?.();
864+
focusedNode.performAction?.(e);
865865
return true;
866866
}
867867
return false;

packages/blockly/tests/mocha/shortcut_items_test.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1037,6 +1037,10 @@ suite('Keyboard Shortcut Items', function () {
10371037
});
10381038

10391039
test('Inserts blocks from the flyout in move mode', function () {
1040+
const first = this.workspace.newBlock('stack_block');
1041+
first.initSvg();
1042+
first.render();
1043+
10401044
this.workspace.getToolbox().selectItemByPosition(0);
10411045
const block = this.workspace
10421046
.getNavigator()
@@ -1053,6 +1057,12 @@ suite('Keyboard Shortcut Items', function () {
10531057
assert.isTrue(movingBlock.isDragging());
10541058
assert.isFalse(movingBlock.workspace.isFlyout);
10551059

1060+
const hasInsertionMarker = this.workspace
1061+
.getTopBlocks()
1062+
.flatMap((b) => b.getChildren())
1063+
.some((b) => b.isInsertionMarker());
1064+
assert.isTrue(hasInsertionMarker);
1065+
10561066
Blockly.KeyboardMover.mover.abortMove();
10571067
});
10581068

0 commit comments

Comments
 (0)