From cc3b19101809742e0e587537f332c8c924205383 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Thu, 21 May 2026 11:22:16 -0700 Subject: [PATCH 1/2] fix: Correctly position blocks dragged by the mouse from the flyout --- .../core/dragging/block_drag_strategy.ts | 34 +++++++++++++++---- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/packages/blockly/core/dragging/block_drag_strategy.ts b/packages/blockly/core/dragging/block_drag_strategy.ts index 2f4820e9aa2..193e078b966 100644 --- a/packages/blockly/core/dragging/block_drag_strategy.ts +++ b/packages/blockly/core/dragging/block_drag_strategy.ts @@ -36,6 +36,7 @@ import {Coordinate} from '../utils.js'; import * as aria from '../utils/aria.js'; import * as dom from '../utils/dom.js'; import {Rect} from '../utils/rect.js'; +import * as svgMath from '../utils/svg_math.js'; import type {WorkspaceSvg} from '../workspace_svg.js'; /** Represents a valid pair of connections between the dragging block and a block on the workspace. */ @@ -117,9 +118,21 @@ export class BlockDragStrategy implements IDragStrategy { /** * Positions a cloned block on its new workspace. * + * @param oldBlock The flyout block that was cloned. * @param newBlock The new block to position. */ - private positionNewBlock(newBlock: BlockSvg) { + private positionNewBlock(oldBlock: BlockSvg, newBlock: BlockSvg) { + const screenCoordinate = svgMath.wsToScreenCoordinates( + oldBlock.workspace, + oldBlock.getRelativeToSurfaceXY(), + ); + const workspaceCoordinates = svgMath.screenToWsCoordinates( + newBlock.workspace, + screenCoordinate, + ); + newBlock.moveDuringDrag(workspaceCoordinates); + + if (this.moveMode !== MoveMode.CONSTRAINED) return; const workspace = newBlock.workspace; const initialY = this.WORKSPACE_MARGIN; const initialX = this.WORKSPACE_MARGIN; @@ -223,7 +236,7 @@ export class BlockDragStrategy implements IDragStrategy { }, ) as BlockSvg; eventUtils.setRecordUndo(false); - this.positionNewBlock(newBlock); + this.positionNewBlock(this.block, newBlock); eventUtils.setRecordUndo(true); return newBlock; @@ -290,6 +303,7 @@ export class BlockDragStrategy implements IDragStrategy { * from any parent blocks. */ startDrag(e?: PointerEvent | KeyboardEvent) { + this.updateMoveMode(e); const alternateTarget = this.getTargetBlock(); if (alternateTarget !== this.block) { return alternateTarget.startDrag(e); @@ -549,11 +563,7 @@ export class BlockDragStrategy implements IDragStrategy { /** Moves the block and updates any connection previews. */ drag(newLoc: Coordinate, e?: PointerEvent | KeyboardEvent): void { - this.moveMode = - e instanceof KeyboardEvent && !(e.ctrlKey || e.metaKey) - ? MoveMode.CONSTRAINED - : MoveMode.UNCONSTRAINED; - + this.updateMoveMode(e); if (this.moveMode === MoveMode.UNCONSTRAINED) { this.block.moveDuringDrag(newLoc); } @@ -1216,4 +1226,14 @@ export class BlockDragStrategy implements IDragStrategy { return null; } + + /** + * Updates the current move mode based on the most recent drag-related event. + */ + private updateMoveMode(event: KeyboardEvent | PointerEvent | undefined) { + this.moveMode = + event instanceof KeyboardEvent && !(event.ctrlKey || event.metaKey) + ? MoveMode.CONSTRAINED + : MoveMode.UNCONSTRAINED; + } } From cfa627aaa1b82a3040cf864644b05be9c2692e7e Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Thu, 21 May 2026 11:22:27 -0700 Subject: [PATCH 2/2] fix: Fix incidental test breakage --- packages/blockly/tests/mocha/keyboard_movement_test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/blockly/tests/mocha/keyboard_movement_test.js b/packages/blockly/tests/mocha/keyboard_movement_test.js index 79b94e32e23..35450e85fa6 100644 --- a/packages/blockly/tests/mocha/keyboard_movement_test.js +++ b/packages/blockly/tests/mocha/keyboard_movement_test.js @@ -1262,7 +1262,7 @@ suite('Keyboard-driven movement', function () { this.clock.tick(10); this.moveAndAssert( moveRight, - ['Moving', 'else if, do', 'around', 'draw', '❤️'], + ['Moving', 'else', 'around', 'draw', '❤️'], ['of'], ); this.moveAndAssert(