-
Notifications
You must be signed in to change notification settings - Fork 3.8k
fix: Fix bug in BlockSvg.prototype.setParent
#8934
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Add tests for scenarios where block(s) unrelated to the block being disconnected has/have been marked as as being dragged. Due to a bug in BlockSvg.prototype.setParent, one of these fails in the case that the dragging block is not a top block. Also add a check to assertNonParentAndOrphan to check that the orphan block's SVG root's parent is the workspace's canvass (i.e., that orphan is a top-level block in the DOM too).
Fix an incorrect assumption in setParent: the topmost block whose root SVG element has the blocklyDragging class may not actually be a top-level block.
rachel-fenichel
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM after minor fixes.
core/block_svg.ts
Outdated
| | SVGElement | ||
| | null | ||
| | undefined; | ||
| const canvass = this.workspace.getCanvas(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: canvass - > canvas
core/dragging/block_drag_strategy.ts
Outdated
| return; | ||
| } | ||
|
|
||
| this.connectionPreviewer!.hidePreview(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Switch to ?. instead of !. while you're at it.
The basics
The details
Resolves
Fix an incorrect assumption in
setParentwhen handling.setParent(null)calls.Fixes #8853.
(But see comments on that bug for detail.)
Proposed Changes
BlockSvg.prototype.setParent, when setting parent tonull, check to see if the top-mostblocklyDraggingelement is in fact a direct child of the canvass before attempting to insert the new top-level block ahead of it in the canvass's contents.BlockDragStragegy.prototype.revertDrag, callconnectionPreviewer.hidePreview()earlier, before attempting to reconnect the dragged block to its original parent. Not strictly necessary but makes more sense.BlockSvgandBlockDragStrategy.Reason for Changes
The topmost block whose root SVG element has the
blocklyDraggingclass may not actually be a top-level block on the workspace, but the existing implementation assumed that was true and would throw an error if it wasn't. This resulted in problems when reverting a drag if an insertion marker was displayed.Test Coverage
Adds two new tests for
setParent(one of which actually caught a bug that existed in an earlier version of the fix in this PR!)