fix: Always draw dragged blocks atop others in the workspace. (#6874)

* fix: Always draw dragged blocks atop others in the workspace.

* chore: format

---------

Co-authored-by: Beka Westberg <bwestberg@google.com>
This commit is contained in:
Aaron Dodson
2023-08-21 14:58:30 -07:00
committed by GitHub
parent a0301a217a
commit 9909868435
2 changed files with 16 additions and 9 deletions

View File

@@ -105,13 +105,10 @@ export class BlockDragger implements IBlockDragger {
}
this.fireDragStartEvent_();
// Mutators don't have the same type of z-ordering as the normal workspace
// during a drag. They have to rely on the order of the blocks in the SVG.
// For performance reasons that usually happens at the end of a drag,
// but do it at the beginning for mutators.
if (this.workspace_.isMutator) {
this.draggingBlock_.bringToFront();
}
// The z-order of blocks depends on their order in the SVG, so move the
// block being dragged to the front so that it will appear atop other blocks
// in the workspace.
this.draggingBlock_.bringToFront(true);
// During a drag there may be a lot of rerenders, but not field changes.
// Turn the cache on so we don't do spurious remeasures during the drag.

View File

@@ -328,7 +328,14 @@ export class BlockSvg
} else if (oldParent) {
// If we are losing a parent, we want to move our DOM element to the
// root of the workspace.
this.workspace.getCanvas().appendChild(svgRoot);
const draggingBlock = this.workspace
.getCanvas()
.querySelector('.blocklyDragging');
if (draggingBlock) {
this.workspace.getCanvas().insertBefore(svgRoot, draggingBlock);
} else {
this.workspace.getCanvas().appendChild(svgRoot);
}
this.translate(oldXY.x, oldXY.y);
}
@@ -1146,9 +1153,11 @@ export class BlockSvg
* order that they are in the DOM. By placing this block first within the
* block group's <g>, it will render on top of any other blocks.
*
* @param blockOnly: True to only move this block to the front without
* adjusting its parents.
* @internal
*/
bringToFront() {
bringToFront(blockOnly = false) {
/* eslint-disable-next-line @typescript-eslint/no-this-alias */
let block: this | null = this;
do {
@@ -1159,6 +1168,7 @@ export class BlockSvg
if (childNodes[childNodes.length - 1] !== root) {
parent!.appendChild(root);
}
if (blockOnly) break;
block = block.getParent();
} while (block);
}