diff --git a/js/listeners/KeyboardDragListener.ts b/js/listeners/KeyboardDragListener.ts index ac574d0ab..64cfb7429 100644 --- a/js/listeners/KeyboardDragListener.ts +++ b/js/listeners/KeyboardDragListener.ts @@ -152,6 +152,7 @@ class KeyboardDragListener extends KeyboardListener; private dragEndAction: PhetioAction; + private dragAction: PhetioAction; // KeyboardDragListener is implemented with KeyboardListener and therefore Hotkey. Hotkeys use 'global' DOM events // instead of SceneryEvent dispatch. In order to start the drag with a SceneryEvent, this listener waits @@ -232,18 +233,6 @@ class KeyboardDragListener extends KeyboardListener { + assert && assert( this.isPressedProperty.value, 'The listener should not be dragging if not pressed' ); + + // synchronize with model position + if ( this._positionProperty ) { + let newPosition = this._positionProperty.value.plus( this.vectorDelta ); + newPosition = this.mapModelPoint( newPosition ); + + // update the position if it is different + if ( !newPosition.equals( this._positionProperty.value ) ) { + this._positionProperty.value = newPosition; + } + } + + // the optional drag function at the end of any movement + if ( this._drag ) { + assert && assert( this._pointer, 'the pointer must be assigned at the start of a drag action' ); + const syntheticEvent = this.createSyntheticEvent( this._pointer! ); + this._drag( syntheticEvent, this ); + } + }, { + parameters: [], + tandem: options.tandem.createTandem( 'dragAction' ), + phetioDocumentation: 'Emits every time there is some input from a keyboard drag.', + phetioHighFrequency: true, + phetioReadOnly: options.phetioReadOnly, + phetioEventType: EventType.USER + } ); + this.dragEndAction = new PhetioAction( () => { // stop the callback timer @@ -361,25 +383,8 @@ class KeyboardDragListener extends KeyboardListener