Skip to content

Conversation

@rachel-fenichel
Copy link
Collaborator

Fixes #395

When starting a drag, walk up the tree until the first non-shadow block and drag it. If there's no non-shadow block, throw because that's not supposed to happen.

This matches related code in core.

The core code can't handle this case because the drag strategy of the moving block needs to be patched. We're doing that in mover.ts, and getting the correct block in mover.ts means that we don't have to track patching/unpatching the drag strategy on multiple blocks.

@rachel-fenichel rachel-fenichel requested a review from a team as a code owner April 7, 2025 20:43
@rachel-fenichel rachel-fenichel requested review from BenHenning and removed request for a team and BenHenning April 7, 2025 20:43
@rachel-fenichel
Copy link
Collaborator Author

@microbit-matt-hillsdon please review.

const curNode = workspace?.getCursor()?.getCurNode();
let block = curNode?.getSourceBlock();
if (!block) return undefined;
while (block && block.isShadow()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Because we check !block before and in the loop, this test can just be block.isShadow(). Makes it a bit clearer that block is always defined after the loop.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It can return null from getParent. It'll be an error (see below), but still possible in the type system.

Copy link
Contributor

@microbit-matt-hillsdon microbit-matt-hillsdon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rachel-fenichel rachel-fenichel merged commit 466949a into RaspberryPiFoundation:main Apr 8, 2025
2 checks passed
@rachel-fenichel rachel-fenichel deleted the drag_shadow branch April 8, 2025 15:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Move starting with the cursor on a shadow block doesn't work

2 participants