Skip to content

Commit dce3315

Browse files
authored
fix: position dragging block above/below all blocks (#9972)
* fix: position dragging block above/below all blocks * fix: linting * chore: remove unnecessary argument
1 parent 23c08ac commit dce3315

1 file changed

Lines changed: 12 additions & 6 deletions

File tree

packages/blockly/core/dragging/block_drag_strategy.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -664,25 +664,31 @@ export class BlockDragStrategy implements IDragStrategy {
664664
const bounds = root?.getBoundingRectangle();
665665
if (!bounds) return;
666666

667+
const blockRects = draggingBlock.workspace
668+
.getTopBlocks()
669+
.map((block) => block.getBoundingRectangle());
670+
const blocksLeft = Math.min(...blockRects.map((rect) => rect.left));
671+
667672
let destination: Coordinate;
673+
let blockBound: number;
668674
switch (direction) {
669675
case Direction.LEFT:
670676
case Direction.UP:
677+
blockBound = Math.min(...blockRects.map((rect) => rect.top));
671678
destination = new Coordinate(
672-
bounds.getOrigin().x,
673-
bounds.getOrigin().y -
679+
blocksLeft,
680+
blockBound -
674681
this.BLOCK_CONNECTION_OFFSET * 2 -
675682
draggingBlock.getHeightWidth().height,
676683
);
677684
break;
678685
case Direction.RIGHT:
679686
case Direction.DOWN:
680687
default:
688+
blockBound = Math.max(...blockRects.map((rect) => rect.bottom));
681689
destination = new Coordinate(
682-
bounds.getOrigin().x,
683-
bounds.getOrigin().y +
684-
bounds.getHeight() +
685-
this.BLOCK_CONNECTION_OFFSET * 2,
690+
blocksLeft,
691+
blockBound + this.BLOCK_CONNECTION_OFFSET * 2,
686692
);
687693
break;
688694
}

0 commit comments

Comments
 (0)