@@ -371,6 +371,94 @@ export class DragMouseHandler extends MouseHandlerWithSnapLines {
371
371
} ) ;
372
372
}
373
373
374
+ getConnectionLineAlignedY ( context : IFlowContext , event : IPointerEvent ) {
375
+ if ( ! event . ctrlKey ) {
376
+ return undefined ;
377
+ }
378
+
379
+ let foundConnectionLine ;
380
+ let foundDx = 0 ;
381
+
382
+ for ( const connectionLine of ( context . document . flow . object as Flow )
383
+ . connectionLines ) {
384
+ if (
385
+ this . selectedObjects . find (
386
+ selectedObject =>
387
+ selectedObject . object == connectionLine . sourceComponent
388
+ )
389
+ ) {
390
+ // skip connection lines where source is among selected objects
391
+ continue ;
392
+ }
393
+
394
+ const selectedObject = this . selectedObjects . find (
395
+ selectedObject =>
396
+ selectedObject . object == connectionLine . targetComponent
397
+ ) ;
398
+ if ( selectedObject ) {
399
+ const sourceOutputX =
400
+ connectionLine . sourceComponent . geometry . left +
401
+ connectionLine . sourceComponent . geometry . outputs [
402
+ connectionLine . output
403
+ ] . position . x ;
404
+
405
+ const targetInputX =
406
+ this . rects [
407
+ this . selectedObjects . findIndex (
408
+ selectedObject =>
409
+ selectedObject . object ==
410
+ connectionLine . targetComponent
411
+ )
412
+ ] . left +
413
+ connectionLine . targetComponent . geometry . inputs [
414
+ connectionLine . input
415
+ ] . position . x ;
416
+
417
+ const dx = targetInputX - sourceOutputX ;
418
+
419
+ if (
420
+ dx > 0 &&
421
+ ( ! foundConnectionLine || Math . abs ( dx ) < Math . abs ( foundDx ) )
422
+ ) {
423
+ foundConnectionLine = connectionLine ;
424
+ foundDx = dx ;
425
+ }
426
+ }
427
+ }
428
+
429
+ if ( ! foundConnectionLine ) {
430
+ return undefined ;
431
+ }
432
+
433
+ const topSource = foundConnectionLine . sourceComponent . top ;
434
+
435
+ const topBounding = this . selectionBoundingRectAtDown . top ;
436
+ const topTarget =
437
+ this . objectPositionsAtDown [
438
+ this . selectedObjects . findIndex (
439
+ selectedObject =>
440
+ selectedObject . object ==
441
+ foundConnectionLine . targetComponent
442
+ )
443
+ ] . y ;
444
+
445
+ const sourceOutputY =
446
+ foundConnectionLine . sourceComponent . geometry . outputs [
447
+ foundConnectionLine . output
448
+ ] . position . y ;
449
+
450
+ const targetInputY =
451
+ foundConnectionLine . targetComponent . geometry . inputs [
452
+ foundConnectionLine . input
453
+ ] . position . y ;
454
+
455
+ return (
456
+ topSource +
457
+ ( topBounding - topTarget ) -
458
+ ( targetInputY - sourceOutputY )
459
+ ) ;
460
+ }
461
+
374
462
down ( context : IFlowContext , event : IPointerEvent ) {
375
463
super . down ( context , event ) ;
376
464
@@ -403,13 +491,21 @@ export class DragMouseHandler extends MouseHandlerWithSnapLines {
403
491
return ;
404
492
}
405
493
406
- const { left, top } = this . snapLines . dragSnap (
494
+ let { left, top } = this . snapLines . dragSnap (
407
495
this . left ,
408
496
this . top ,
409
497
this . selectionBoundingRectAtDown . width ,
410
498
this . selectionBoundingRectAtDown . height
411
499
) ;
412
500
501
+ const connectionLineAlignedY = this . getConnectionLineAlignedY (
502
+ context ,
503
+ event
504
+ ) ;
505
+ if ( connectionLineAlignedY ) {
506
+ top = connectionLineAlignedY ;
507
+ }
508
+
413
509
const viewState = context . viewState ;
414
510
415
511
viewState . dxMouseDrag = left - this . selectionBoundingRectAtDown . left ;
0 commit comments