From dce3315faa0a780db3cf2e33743f001251f9dabf Mon Sep 17 00:00:00 2001 From: Michael Harvey <43474485+mikeharv@users.noreply.github.com> Date: Wed, 10 Jun 2026 14:53:35 -0400 Subject: [PATCH] fix: position dragging block above/below all blocks (#9972) * fix: position dragging block above/below all blocks * fix: linting * chore: remove unnecessary argument --- .../core/dragging/block_drag_strategy.ts | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/packages/blockly/core/dragging/block_drag_strategy.ts b/packages/blockly/core/dragging/block_drag_strategy.ts index 82272d3e7..445883ab2 100644 --- a/packages/blockly/core/dragging/block_drag_strategy.ts +++ b/packages/blockly/core/dragging/block_drag_strategy.ts @@ -664,13 +664,20 @@ export class BlockDragStrategy implements IDragStrategy { const bounds = root?.getBoundingRectangle(); if (!bounds) return; + const blockRects = draggingBlock.workspace + .getTopBlocks() + .map((block) => block.getBoundingRectangle()); + const blocksLeft = Math.min(...blockRects.map((rect) => rect.left)); + let destination: Coordinate; + let blockBound: number; switch (direction) { case Direction.LEFT: case Direction.UP: + blockBound = Math.min(...blockRects.map((rect) => rect.top)); destination = new Coordinate( - bounds.getOrigin().x, - bounds.getOrigin().y - + blocksLeft, + blockBound - this.BLOCK_CONNECTION_OFFSET * 2 - draggingBlock.getHeightWidth().height, ); @@ -678,11 +685,10 @@ export class BlockDragStrategy implements IDragStrategy { case Direction.RIGHT: case Direction.DOWN: default: + blockBound = Math.max(...blockRects.map((rect) => rect.bottom)); destination = new Coordinate( - bounds.getOrigin().x, - bounds.getOrigin().y + - bounds.getHeight() + - this.BLOCK_CONNECTION_OFFSET * 2, + blocksLeft, + blockBound + this.BLOCK_CONNECTION_OFFSET * 2, ); break; }