Skip to content

Commit 466949a

Browse files
fix: drag parent of shadow block (#399)
1 parent 5d01bcc commit 466949a

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

src/actions/mover.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -218,15 +218,27 @@ export class Mover {
218218
/**
219219
* Get the source block for the cursor location, or undefined if no
220220
* source block can be found.
221+
* If the cursor is on a shadow block, walks up the tree until it finds
222+
* a non-shadow block to drag.
221223
*
222224
* @param workspace The workspace to inspect for a cursor.
223225
* @returns The source block, or undefined if no appropriate block
224226
* could be found.
225227
*/
226228
protected getCurrentBlock(workspace: WorkspaceSvg): BlockSvg | undefined {
227-
const cursor = workspace?.getCursor();
228-
const curNode = cursor?.getCurNode();
229-
return (curNode?.getSourceBlock() as BlockSvg) ?? undefined;
229+
const curNode = workspace?.getCursor()?.getCurNode();
230+
let block = curNode?.getSourceBlock();
231+
if (!block) return undefined;
232+
while (block && block.isShadow()) {
233+
block = block.getParent();
234+
if (!block) {
235+
throw new Error(
236+
'Tried to drag a shadow block with no parent. ' +
237+
'Shadow blocks should always have parents.',
238+
);
239+
}
240+
}
241+
return block as BlockSvg;
230242
}
231243

232244
/**

0 commit comments

Comments
 (0)