From be007d0a56924130df1a5fad811fcf53f92a59ea Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Mon, 7 Apr 2025 13:40:50 -0700 Subject: [PATCH] fix: drag parent of shadow block --- src/actions/mover.ts | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/actions/mover.ts b/src/actions/mover.ts index dd84b9c5..6e4f06ee 100644 --- a/src/actions/mover.ts +++ b/src/actions/mover.ts @@ -218,15 +218,27 @@ export class Mover { /** * Get the source block for the cursor location, or undefined if no * source block can be found. + * If the cursor is on a shadow block, walks up the tree until it finds + * a non-shadow block to drag. * * @param workspace The workspace to inspect for a cursor. * @returns The source block, or undefined if no appropriate block * could be found. */ protected getCurrentBlock(workspace: WorkspaceSvg): BlockSvg | undefined { - const cursor = workspace?.getCursor(); - const curNode = cursor?.getCurNode(); - return (curNode?.getSourceBlock() as BlockSvg) ?? undefined; + const curNode = workspace?.getCursor()?.getCurNode(); + let block = curNode?.getSourceBlock(); + if (!block) return undefined; + while (block && block.isShadow()) { + block = block.getParent(); + if (!block) { + throw new Error( + 'Tried to drag a shadow block with no parent. ' + + 'Shadow blocks should always have parents.', + ); + } + } + return block as BlockSvg; } /**