Skip to content

Commit fc76981

Browse files
Merge pull request #7482 from clementcontet/fix-7426
fix: insertion marker position when connection is resized (#7426)
2 parents 1f0f733 + 36b00fb commit fc76981

2 files changed

Lines changed: 22 additions & 7 deletions

File tree

core/block_svg.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1515,22 +1515,27 @@ export class BlockSvg
15151515
* or an insertion marker.
15161516
*
15171517
* @param sourceConnection The connection on the moving block's stack.
1518-
* @param targetConnection The connection that should stay stationary as this
1519-
* block is positioned.
1518+
* @param originalOffsetToTarget The connection original offset to the target connection
1519+
* @param originalOffsetInBlock The connection original offset in its block
15201520
* @internal
15211521
*/
15221522
positionNearConnection(
15231523
sourceConnection: RenderedConnection,
1524-
targetConnection: RenderedConnection,
1524+
originalOffsetToTarget: {x: number; y: number},
1525+
originalOffsetInBlock: Coordinate,
15251526
) {
15261527
// We only need to position the new block if it's before the existing one,
15271528
// otherwise its position is set by the previous block.
15281529
if (
15291530
sourceConnection.type === ConnectionType.NEXT_STATEMENT ||
15301531
sourceConnection.type === ConnectionType.INPUT_VALUE
15311532
) {
1532-
const dx = targetConnection.x - sourceConnection.x;
1533-
const dy = targetConnection.y - sourceConnection.y;
1533+
// First move the block to match the orginal target connection position
1534+
let dx = originalOffsetToTarget.x;
1535+
let dy = originalOffsetToTarget.y;
1536+
// Then adjust its position according to the connection resize
1537+
dx += originalOffsetInBlock.x - sourceConnection.getOffsetInBlock().x;
1538+
dy += originalOffsetInBlock.y - sourceConnection.getOffsetInBlock().y;
15341539

15351540
this.moveBy(dx, dy);
15361541
}

core/insertion_marker_manager.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -611,12 +611,22 @@ export class InsertionMarkerManager {
611611
insertionMarker.queueRender();
612612
renderManagement.triggerQueuedRenders();
613613

614-
// Position so that the existing block doesn't move.
615-
insertionMarker.positionNearConnection(imConn, closest);
616614
// Connect() also renders the insertion marker.
617615
imConn.connect(closest);
618616

617+
const originalOffsetToTarget = {
618+
x: closest.x - imConn.x,
619+
y: closest.y - imConn.y,
620+
};
621+
const originalOffsetInBlock = imConn.getOffsetInBlock().clone();
622+
const imConnConst = imConn;
619623
renderManagement.finishQueuedRenders().then(() => {
624+
// Position so that the existing block doesn't move.
625+
insertionMarker?.positionNearConnection(
626+
imConnConst,
627+
originalOffsetToTarget,
628+
originalOffsetInBlock,
629+
);
620630
insertionMarker?.getSvgRoot().setAttribute('visibility', 'visible');
621631
});
622632

0 commit comments

Comments
 (0)