Skip to content

Commit 75de6cb

Browse files
fix: Improve fallback for getInitialCandidate (#9941)
* fix: Improve fallback for getInitialCandidate * Improve variable name
1 parent 695e071 commit 75de6cb

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

packages/blockly/core/dragging/block_drag_strategy.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1238,6 +1238,19 @@ export class BlockDragStrategy implements IDragStrategy {
12381238
return this.pairToCandidate(parentPair);
12391239
}
12401240

1241+
// Fall back to the nearest parent block that has a compatible connection.
1242+
// This handles the case where a nested value block (e.g. a number input)
1243+
// has passive focus but the dragged block is a statement block that should
1244+
// be inserted after the containing statement block.
1245+
let parentBlock = passiveBlock.getSurroundParent();
1246+
while (parentBlock) {
1247+
const pair = this.allConnectionPairs.find(
1248+
(pair) => pair.neighbour.getSourceBlock() === parentBlock,
1249+
);
1250+
if (pair) return this.pairToCandidate(pair);
1251+
parentBlock = parentBlock.getSurroundParent();
1252+
}
1253+
12411254
return null;
12421255
}
12431256

0 commit comments

Comments
 (0)