File tree Expand file tree Collapse file tree 2 files changed +29
-6
lines changed
Expand file tree Collapse file tree 2 files changed +29
-6
lines changed Original file line number Diff line number Diff line change @@ -336,6 +336,8 @@ export class Mover {
336336 info . fakePointerEvent ( 'pointermove' , direction ) ,
337337 info . totalDelta ,
338338 ) ;
339+
340+ info . updateTotalDelta ( ) ;
339341 return true ;
340342 }
341343
@@ -426,7 +428,7 @@ export class Mover {
426428 * Workspace.
427429 */
428430export class MoveInfo {
429- /** Total distance moved, in screen pixels */
431+ /** Total distance moved, in workspace units. */
430432 totalDelta = new utils . Coordinate ( 0 , 0 ) ;
431433 readonly parentNext : Connection | null ;
432434 readonly parentInput : Connection | null ;
@@ -468,4 +470,19 @@ export class MoveInfo {
468470 tiltY : tilts . y ,
469471 } ) ;
470472 }
473+
474+ /**
475+ * The keyboard drag may have moved the block to an appropriate location
476+ * for a preview. Update the saved delta to reflect the block's new
477+ * location, so that it does not jump during the next unconstrained move.
478+ */
479+ updateTotalDelta ( ) {
480+ const workspace = this . block . workspace ;
481+ if ( ! ( workspace instanceof WorkspaceSvg ) ) throw new TypeError ( ) ;
482+
483+ this . totalDelta = new utils . Coordinate (
484+ this . block . relativeCoords . x - this . startLocation . x ,
485+ this . block . relativeCoords . y - this . startLocation . y ,
486+ ) ;
487+ }
471488}
Original file line number Diff line number Diff line change @@ -44,13 +44,19 @@ export class KeyboardDragStrategy extends dragging.BlockDragStrategy {
4444 super . drag ( newLoc ) ;
4545
4646 // Handle the case when an unconstrained drag found a connection candidate.
47- // The next constrained move will resume the search from the current candidate
48- // location.
4947 // @ts -expect-error connectionCandidate is private.
5048 if ( this . connectionCandidate ) {
51- this . searchNode = ASTNode . createConnectionNode (
52- // @ts -expect-error connectionCandidate is private.
53- ( this . connectionCandidate as ConnectionCandidate ) . neighbour ,
49+ // @ts -expect-error connectionCandidate is private.
50+ const neighbour = ( this . connectionCandidate as ConnectionCandidate )
51+ . neighbour ;
52+ // The next constrained move will resume the search from the current
53+ // candidate location.
54+ this . searchNode = ASTNode . createConnectionNode ( neighbour ) ;
55+ // The moving block will be positioned slightly down and to the
56+ // right of the connection it found.
57+ // @ts -expect-error block and startLoc are private.
58+ this . block . moveDuringDrag (
59+ new utils . Coordinate ( neighbour . x + 10 , neighbour . y + 10 ) ,
5460 ) ;
5561 }
5662 }
You can’t perform that action at this time.
0 commit comments