From fc05769f195c3e871db2c05f39c278f506f76a04 Mon Sep 17 00:00:00 2001 From: Jesse Date: Thu, 25 Apr 2024 19:16:12 -0400 Subject: [PATCH] remove dragEmitter, replace with dragAction, see https://github.com/phetsims/scenery/issues/1570 --- js/listeners/KeyboardDragListener.ts | 65 +++++++++++++++------------- 1 file changed, 35 insertions(+), 30 deletions(-) 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