Skip to content

Commit a2a9ab1

Browse files
committed
fix: insertion marker position when connection is resized (#7426)
1 parent 68261e5 commit a2a9ab1

2 files changed

Lines changed: 29 additions & 0 deletions

File tree

core/block_svg.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1536,6 +1536,32 @@ export class BlockSvg
15361536
}
15371537
}
15381538

1539+
/**
1540+
* Reposition a block after its connection has been resized, to match exactly the target block position.
1541+
* The block to position is usually either the first block in a dragged stack
1542+
* or an insertion marker.
1543+
*
1544+
* @param sourceConnection The connection on the moving block's stack.
1545+
* @param originalOffsetInBlock The connection original offset in its block, before the resize occured
1546+
* @internal
1547+
*/
1548+
repositionAfterConnectionResize(
1549+
sourceConnection: RenderedConnection,
1550+
originalOffsetInBlock: Coordinate,
1551+
) {
1552+
// We only need to position the new block if it's before the existing one,
1553+
// otherwise its position is set by the previous block.
1554+
if (
1555+
sourceConnection.type === ConnectionType.NEXT_STATEMENT ||
1556+
sourceConnection.type === ConnectionType.INPUT_VALUE
1557+
) {
1558+
const dx = originalOffsetInBlock.x - sourceConnection.getOffsetInBlock().x;
1559+
const dy = originalOffsetInBlock.y - sourceConnection.getOffsetInBlock().y;
1560+
1561+
this.moveBy(dx, dy);
1562+
}
1563+
}
1564+
15391565
/**
15401566
* Find all the blocks that are directly nested inside this one.
15411567
* Includes value and statement inputs, as well as any following statement.

core/insertion_marker_manager.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -616,8 +616,11 @@ export class InsertionMarkerManager {
616616
// Connect() also renders the insertion marker.
617617
imConn.connect(closest);
618618

619+
let originalOffsetInBlock = imConn.getOffsetInBlock().clone();
620+
const imConnConst = imConn;
619621
renderManagement.finishQueuedRenders().then(() => {
620622
insertionMarker?.getSvgRoot().setAttribute('visibility', 'visible');
623+
insertionMarker?.repositionAfterConnectionResize(imConnConst, originalOffsetInBlock);
621624
});
622625

623626
this.markerConnection = imConn;

0 commit comments

Comments
 (0)