Skip to content

Commit a34d95d

Browse files
authored
fix: Fix visual glitch when dragging blocks (#9901)
1 parent 2f1acb3 commit a34d95d

1 file changed

Lines changed: 33 additions & 32 deletions

File tree

packages/blockly/core/dragging/block_drag_strategy.ts

Lines changed: 33 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -562,40 +562,41 @@ export class BlockDragStrategy implements IDragStrategy {
562562

563563
if (!newCandidate) {
564564
// Position above or below the first/last block.
565-
const connectedBlock = currCandidate?.neighbour.getSourceBlock();
566-
let root = connectedBlock?.getRootBlock() ?? connectedBlock;
567-
if (root === draggingBlock) root = connectedBlock;
568-
const direction = this.getDirectionToNewLocation(
569-
Coordinate.sum(this.startLoc!, delta),
570-
);
571-
const bounds = root?.getBoundingRectangle();
572-
if (!bounds) return;
573-
574-
let destination: Coordinate;
575-
switch (direction) {
576-
case Direction.LEFT:
577-
case Direction.UP:
578-
destination = new Coordinate(
579-
bounds.getOrigin().x,
580-
bounds.getOrigin().y -
581-
this.BLOCK_CONNECTION_OFFSET * 2 -
582-
draggingBlock.getHeightWidth().height,
583-
);
584-
break;
585-
case Direction.RIGHT:
586-
case Direction.DOWN:
587-
default:
588-
destination = new Coordinate(
589-
bounds.getOrigin().x,
590-
bounds.getOrigin().y +
591-
bounds.getHeight() +
592-
this.BLOCK_CONNECTION_OFFSET * 2,
593-
);
594-
break;
565+
if (this.moveMode === MoveMode.CONSTRAINED) {
566+
const connectedBlock = currCandidate?.neighbour.getSourceBlock();
567+
let root = connectedBlock?.getRootBlock() ?? connectedBlock;
568+
if (root === draggingBlock) root = connectedBlock;
569+
const direction = this.getDirectionToNewLocation(
570+
Coordinate.sum(this.startLoc!, delta),
571+
);
572+
const bounds = root?.getBoundingRectangle();
573+
if (!bounds) return;
574+
575+
let destination: Coordinate;
576+
switch (direction) {
577+
case Direction.LEFT:
578+
case Direction.UP:
579+
destination = new Coordinate(
580+
bounds.getOrigin().x,
581+
bounds.getOrigin().y -
582+
this.BLOCK_CONNECTION_OFFSET * 2 -
583+
draggingBlock.getHeightWidth().height,
584+
);
585+
break;
586+
case Direction.RIGHT:
587+
case Direction.DOWN:
588+
default:
589+
destination = new Coordinate(
590+
bounds.getOrigin().x,
591+
bounds.getOrigin().y +
592+
bounds.getHeight() +
593+
this.BLOCK_CONNECTION_OFFSET * 2,
594+
);
595+
break;
596+
}
597+
draggingBlock.moveDuringDrag(destination);
595598
}
596599

597-
draggingBlock.moveDuringDrag(destination);
598-
599600
this.connectionPreviewer?.hidePreview();
600601
this.connectionCandidate = null;
601602
return;

0 commit comments

Comments
 (0)