mirror of
https://github.com/google/blockly.git
synced 2026-01-11 10:57:07 +01:00
fix: insertion marker position when connection is resized (#7426)
This commit is contained in:
@@ -1536,6 +1536,32 @@ export class BlockSvg
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reposition a block after its connection has been resized, to match exactly the target block position.
|
||||
* The block to position is usually either the first block in a dragged stack
|
||||
* or an insertion marker.
|
||||
*
|
||||
* @param sourceConnection The connection on the moving block's stack.
|
||||
* @param originalOffsetInBlock The connection original offset in its block, before the resize occured
|
||||
* @internal
|
||||
*/
|
||||
repositionAfterConnectionResize(
|
||||
sourceConnection: RenderedConnection,
|
||||
originalOffsetInBlock: Coordinate,
|
||||
) {
|
||||
// We only need to position the new block if it's before the existing one,
|
||||
// otherwise its position is set by the previous block.
|
||||
if (
|
||||
sourceConnection.type === ConnectionType.NEXT_STATEMENT ||
|
||||
sourceConnection.type === ConnectionType.INPUT_VALUE
|
||||
) {
|
||||
const dx = originalOffsetInBlock.x - sourceConnection.getOffsetInBlock().x;
|
||||
const dy = originalOffsetInBlock.y - sourceConnection.getOffsetInBlock().y;
|
||||
|
||||
this.moveBy(dx, dy);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Find all the blocks that are directly nested inside this one.
|
||||
* Includes value and statement inputs, as well as any following statement.
|
||||
|
||||
@@ -616,8 +616,11 @@ export class InsertionMarkerManager {
|
||||
// Connect() also renders the insertion marker.
|
||||
imConn.connect(closest);
|
||||
|
||||
let originalOffsetInBlock = imConn.getOffsetInBlock().clone();
|
||||
const imConnConst = imConn;
|
||||
renderManagement.finishQueuedRenders().then(() => {
|
||||
insertionMarker?.getSvgRoot().setAttribute('visibility', 'visible');
|
||||
insertionMarker?.repositionAfterConnectionResize(imConnConst, originalOffsetInBlock);
|
||||
});
|
||||
|
||||
this.markerConnection = imConn;
|
||||
|
||||
Reference in New Issue
Block a user