@@ -26,6 +26,23 @@ export default function widgetBehavior(publicAPI, model) {
2626 publicAPI . getHandle = ( handleIndex ) =>
2727 model . widgetState [ handleGetters [ handleIndex ] ] ( ) ;
2828
29+ /**
30+ * Return the index in the of tbe handle in `representations` array,
31+ * or -1 if the handle is not present in the widget state.
32+ */
33+ publicAPI . getHandleIndex = ( handle ) => {
34+ switch ( handle ) {
35+ case model . widgetState . getHandle1 ( ) :
36+ return 0 ;
37+ case model . widgetState . getHandle2 ( ) :
38+ return 1 ;
39+ case model . widgetState . getMoveHandle ( ) :
40+ return 2 ;
41+ default :
42+ return - 1 ;
43+ }
44+ } ;
45+
2946 publicAPI . isPlaced = ( ) =>
3047 getNumberOfPlacedHandles ( model . widgetState ) === MAX_POINTS ;
3148
@@ -159,12 +176,6 @@ export default function widgetBehavior(publicAPI, model) {
159176
160177 // Handles visibility ---------------------------------------------------------
161178
162- publicAPI . setMoveHandleVisibility = ( visibility ) => {
163- model . representations [ 2 ] . setVisibilityFlagArray ( [ visibility , visibility ] ) ;
164- model . widgetState . getMoveHandle ( ) . setVisible ( visibility ) ;
165- model . representations [ 2 ] . updateActorVisibility ( ) ;
166- } ;
167-
168179 /**
169180 * Set actor visibility to true unless it is a NONE handle
170181 * and uses state visibility variable for the displayActor visibility to
@@ -212,7 +223,7 @@ export default function widgetBehavior(publicAPI, model) {
212223 }
213224 if ( handleIndex === 1 ) {
214225 publicAPI . placeText ( ) ;
215- publicAPI . setMoveHandleVisibility ( false ) ;
226+ publicAPI . loseFocus ( ) ;
216227 }
217228 } ;
218229
@@ -278,6 +289,9 @@ export default function widgetBehavior(publicAPI, model) {
278289 ) {
279290 if ( model . activeState . setOrigin ) {
280291 model . activeState . setOrigin ( worldCoords ) ;
292+ publicAPI . updateHandleVisibility (
293+ publicAPI . getHandleIndex ( model . activeState )
294+ ) ;
281295 } else {
282296 // Dragging line
283297 publicAPI
@@ -355,7 +369,6 @@ export default function widgetBehavior(publicAPI, model) {
355369 if ( ! model . hasFocus && ! publicAPI . isPlaced ( ) ) {
356370 model . activeState = model . widgetState . getMoveHandle ( ) ;
357371 model . activeState . setShape ( publicAPI . getHandle ( 0 ) . getShape ( ) ) ;
358- publicAPI . setMoveHandleVisibility ( true ) ;
359372 model . activeState . activate ( ) ;
360373 model . _interactor . requestAnimation ( publicAPI ) ;
361374 publicAPI . invokeStartInteractionEvent ( ) ;
@@ -372,6 +385,7 @@ export default function widgetBehavior(publicAPI, model) {
372385 }
373386 model . widgetState . deactivate ( ) ;
374387 model . widgetState . getMoveHandle ( ) . deactivate ( ) ;
388+ model . widgetState . getMoveHandle ( ) . setOrigin ( null ) ;
375389 model . activeState = null ;
376390 model . hasFocus = false ;
377391 model . _widgetManager . enablePicking ( ) ;
0 commit comments