From 9cb2ef0231c8335f344a6e2ffa76480d745d2c47 Mon Sep 17 00:00:00 2001 From: Robert Knight Date: Wed, 27 May 2026 14:01:17 +0100 Subject: [PATCH 1/2] fix: Improve fallback for getInitialCandidate --- .../blockly/core/dragging/block_drag_strategy.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/packages/blockly/core/dragging/block_drag_strategy.ts b/packages/blockly/core/dragging/block_drag_strategy.ts index df309d5c854..b6a28bbe974 100644 --- a/packages/blockly/core/dragging/block_drag_strategy.ts +++ b/packages/blockly/core/dragging/block_drag_strategy.ts @@ -1238,6 +1238,19 @@ export class BlockDragStrategy implements IDragStrategy { return this.pairToCandidate(parentPair); } + // Fall back to the nearest parent block that has a compatible connection. + // This handles the case where a nested value block (e.g. a number input) + // has passive focus but the dragged block is a statement block that should + // be inserted after the containing statement block. + let ancestorBlock = passiveBlock.getSurroundParent(); + while (ancestorBlock) { + const pair = this.allConnectionPairs.find( + (pair) => pair.neighbour.getSourceBlock() === ancestorBlock, + ); + if (pair) return this.pairToCandidate(pair); + ancestorBlock = ancestorBlock.getSurroundParent(); + } + return null; } From c02984151df45e0cf0694c327f634a95d16f1670 Mon Sep 17 00:00:00 2001 From: Robert Knight Date: Wed, 27 May 2026 14:10:54 +0100 Subject: [PATCH 2/2] Improve variable name --- packages/blockly/core/dragging/block_drag_strategy.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/blockly/core/dragging/block_drag_strategy.ts b/packages/blockly/core/dragging/block_drag_strategy.ts index b6a28bbe974..a856b81a9dc 100644 --- a/packages/blockly/core/dragging/block_drag_strategy.ts +++ b/packages/blockly/core/dragging/block_drag_strategy.ts @@ -1242,13 +1242,13 @@ export class BlockDragStrategy implements IDragStrategy { // This handles the case where a nested value block (e.g. a number input) // has passive focus but the dragged block is a statement block that should // be inserted after the containing statement block. - let ancestorBlock = passiveBlock.getSurroundParent(); - while (ancestorBlock) { + let parentBlock = passiveBlock.getSurroundParent(); + while (parentBlock) { const pair = this.allConnectionPairs.find( - (pair) => pair.neighbour.getSourceBlock() === ancestorBlock, + (pair) => pair.neighbour.getSourceBlock() === parentBlock, ); if (pair) return this.pairToCandidate(pair); - ancestorBlock = ancestorBlock.getSurroundParent(); + parentBlock = parentBlock.getSurroundParent(); } return null;