From a34d95d9a55ed3285c6e2052b3bd5d2be45aee2c Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Tue, 19 May 2026 13:34:07 -0700 Subject: [PATCH] fix: Fix visual glitch when dragging blocks (#9901) --- .../core/dragging/block_drag_strategy.ts | 63 ++++++++++--------- 1 file changed, 32 insertions(+), 31 deletions(-) diff --git a/packages/blockly/core/dragging/block_drag_strategy.ts b/packages/blockly/core/dragging/block_drag_strategy.ts index ea5cadc7d..e2585b493 100644 --- a/packages/blockly/core/dragging/block_drag_strategy.ts +++ b/packages/blockly/core/dragging/block_drag_strategy.ts @@ -562,40 +562,41 @@ export class BlockDragStrategy implements IDragStrategy { if (!newCandidate) { // Position above or below the first/last block. - const connectedBlock = currCandidate?.neighbour.getSourceBlock(); - let root = connectedBlock?.getRootBlock() ?? connectedBlock; - if (root === draggingBlock) root = connectedBlock; - const direction = this.getDirectionToNewLocation( - Coordinate.sum(this.startLoc!, delta), - ); - const bounds = root?.getBoundingRectangle(); - if (!bounds) return; + if (this.moveMode === MoveMode.CONSTRAINED) { + const connectedBlock = currCandidate?.neighbour.getSourceBlock(); + let root = connectedBlock?.getRootBlock() ?? connectedBlock; + if (root === draggingBlock) root = connectedBlock; + const direction = this.getDirectionToNewLocation( + Coordinate.sum(this.startLoc!, delta), + ); + const bounds = root?.getBoundingRectangle(); + if (!bounds) return; - let destination: Coordinate; - switch (direction) { - case Direction.LEFT: - case Direction.UP: - destination = new Coordinate( - bounds.getOrigin().x, - bounds.getOrigin().y - - this.BLOCK_CONNECTION_OFFSET * 2 - - draggingBlock.getHeightWidth().height, - ); - break; - case Direction.RIGHT: - case Direction.DOWN: - default: - destination = new Coordinate( - bounds.getOrigin().x, - bounds.getOrigin().y + - bounds.getHeight() + - this.BLOCK_CONNECTION_OFFSET * 2, - ); - break; + let destination: Coordinate; + switch (direction) { + case Direction.LEFT: + case Direction.UP: + destination = new Coordinate( + bounds.getOrigin().x, + bounds.getOrigin().y - + this.BLOCK_CONNECTION_OFFSET * 2 - + draggingBlock.getHeightWidth().height, + ); + break; + case Direction.RIGHT: + case Direction.DOWN: + default: + destination = new Coordinate( + bounds.getOrigin().x, + bounds.getOrigin().y + + bounds.getHeight() + + this.BLOCK_CONNECTION_OFFSET * 2, + ); + break; + } + draggingBlock.moveDuringDrag(destination); } - draggingBlock.moveDuringDrag(destination); - this.connectionPreviewer?.hidePreview(); this.connectionCandidate = null; return;