@@ -18,6 +18,7 @@ import {
1818import type { BlockSvg , IDragger , IDragStrategy } from 'blockly' ;
1919import { Navigation } from '../navigation' ;
2020import { KeyboardDragStrategy } from '../keyboard_drag_strategy' ;
21+ import { Direction , getXYFromDirection } from '../drag_direction' ;
2122
2223const KeyCodes = utils . KeyCodes ;
2324const createSerializedKey = ShortcutRegistry . registry . createSerializedKey . bind (
@@ -87,28 +88,28 @@ export class Mover {
8788 {
8889 name : 'Move left, constrained' ,
8990 preconditionFn : ( workspace ) => this . isMoving ( workspace ) ,
90- callback : ( workspace ) => this . moveConstrained ( workspace /* , ...*/ ) ,
91+ callback : ( workspace ) => this . moveConstrained ( workspace , Direction . Left ) ,
9192 keyCodes : [ KeyCodes . LEFT ] ,
9293 allowCollision : true ,
9394 } ,
9495 {
9596 name : 'Move right unconstrained' ,
9697 preconditionFn : ( workspace ) => this . isMoving ( workspace ) ,
97- callback : ( workspace ) => this . moveConstrained ( workspace /* , ... */ ) ,
98+ callback : ( workspace ) => this . moveConstrained ( workspace , Direction . Right ) ,
9899 keyCodes : [ KeyCodes . RIGHT ] ,
99100 allowCollision : true ,
100101 } ,
101102 {
102103 name : 'Move up, constrained' ,
103104 preconditionFn : ( workspace ) => this . isMoving ( workspace ) ,
104- callback : ( workspace ) => this . moveConstrained ( workspace /* , ... */ ) ,
105+ callback : ( workspace ) => this . moveConstrained ( workspace , Direction . Up ) ,
105106 keyCodes : [ KeyCodes . UP ] ,
106107 allowCollision : true ,
107108 } ,
108109 {
109110 name : 'Move down constrained' ,
110111 preconditionFn : ( workspace ) => this . isMoving ( workspace ) ,
111- callback : ( workspace ) => this . moveConstrained ( workspace /* , ... */ ) ,
112+ callback : ( workspace ) => this . moveConstrained ( workspace , Direction . Down ) ,
112113 keyCodes : [ KeyCodes . DOWN ] ,
113114 allowCollision : true ,
114115 } ,
@@ -320,17 +321,18 @@ export class Mover {
320321 * constrained to valid attachment points (if any).
321322 *
322323 * @param workspace The workspace to move on.
324+ * @param direction The direction to move the dragged item.
323325 * @returns True iff this action applies and has been performed.
324326 */
325- moveConstrained (
326- workspace : WorkspaceSvg ,
327- /* ... */
328- ) {
329- // Not yet implemented. Absorb keystroke to avoid moving cursor.
330- alert ( `Constrained movement not implemented.
327+ moveConstrained ( workspace : WorkspaceSvg , direction : Direction ) {
328+ if ( ! workspace ) return false ;
329+ const info = this . moves . get ( workspace ) ;
330+ if ( ! info ) throw new Error ( 'no move info for workspace' ) ;
331331
332- Use ctrl+arrow or alt+arrow (option+arrow on macOS) for unconstrained move.
333- Use enter to complete the move, or escape to abort.` ) ;
332+ info . dragger . onDrag (
333+ info . fakePointerEvent ( 'pointermove' , direction ) ,
334+ info . totalDelta ,
335+ ) ;
334336 return true ;
335337 }
336338
@@ -446,10 +448,11 @@ export class MoveInfo {
446448 * Create a fake pointer event for dragging.
447449 *
448450 * @param type Which type of pointer event to create.
451+ * @param direction The direction if this movement is a constrained drag.
449452 * @returns A synthetic PointerEvent that can be consumed by Blockly's
450453 * dragging code.
451454 */
452- fakePointerEvent ( type : string ) : PointerEvent {
455+ fakePointerEvent ( type : string , direction ?: Direction ) : PointerEvent {
453456 const workspace = this . block . workspace ;
454457 if ( ! ( workspace instanceof WorkspaceSvg ) ) throw new TypeError ( ) ;
455458
@@ -460,9 +463,12 @@ export class MoveInfo {
460463 this . startLocation . y + this . totalDelta . y ,
461464 ) ,
462465 ) ;
466+ const tilts = getXYFromDirection ( direction ) ;
463467 return new PointerEvent ( type , {
464468 clientX : blockCoords . x ,
465469 clientY : blockCoords . y ,
470+ tiltX : tilts . x ,
471+ tiltY : tilts . y ,
466472 } ) ;
467473 }
468474}
0 commit comments