@@ -23,6 +23,11 @@ const DOUBLE_CLICK_SLIP_DISTANCE_MAX_SQUARED =
2323export default function widgetBehavior ( publicAPI : any , model : any ) {
2424 model . classHierarchy . push ( 'vtkPolygonWidgetBehavior' ) ;
2525
26+ const anotherWidgetHasFocus = ( ) =>
27+ model . _widgetManager
28+ . getWidgets ( )
29+ . some ( ( w : any ) => w !== publicAPI && w . hasFocus ( ) ) ;
30+
2631 const setDragging = ( isDragging : boolean ) => {
2732 model . _dragging = isDragging ;
2833 publicAPI . invokeDraggingEvent ( {
@@ -192,8 +197,6 @@ export default function widgetBehavior(publicAPI: any, model: any) {
192197 if ( model . widgetState . getPlacing ( ) && manipulator ) {
193198 // Dropping first point?
194199 if ( model . widgetState . getHandles ( ) . length === 0 ) {
195- // update variables used by updateActiveStateHandle
196- model . activeState = model . widgetState . getMoveHandle ( ) ;
197200 model . _widgetManager . grabFocus ( publicAPI ) ;
198201 }
199202 updateActiveStateHandle ( event ) ;
@@ -248,8 +251,12 @@ export default function widgetBehavior(publicAPI: any, model: any) {
248251 // So we can rely on getSelections() to be up to date now
249252 overUnselectedHandle = false ;
250253
251- if ( model . hasFocus ) {
252- model . _widgetManager . disablePicking ( ) ;
254+ if ( anotherWidgetHasFocus ( ) ) {
255+ publicAPI . invokeHoverEvent ( {
256+ ...event ,
257+ hovering : false ,
258+ } ) ;
259+ return macro . VOID ;
253260 }
254261
255262 publicAPI . invokeHoverEvent ( {
@@ -336,7 +343,6 @@ export default function widgetBehavior(publicAPI: any, model: any) {
336343 ( model . hasFocus && ! model . activeState ) ||
337344 ( model . activeState && ! model . activeState . getActive ( ) )
338345 ) {
339- // update if mouse hovered over handle/activeState for next onDown
340346 model . _widgetManager . enablePicking ( ) ;
341347 model . _interactor . render ( ) ;
342348 }
@@ -415,13 +421,18 @@ export default function widgetBehavior(publicAPI: any, model: any) {
415421 } ;
416422
417423 publicAPI . handleRightButtonPress = ( eventData : any ) => {
424+ // When placing, handle right-click regardless of what widget manager picked
425+ if ( model . widgetState . getPlacing ( ) ) {
426+ removeLastHandle ( ) ;
427+ return macro . EVENT_ABORT ;
428+ }
429+
418430 if ( ! model . activeState ) {
419431 return macro . VOID ;
420432 }
421433
422- if ( model . widgetState . getPlacing ( ) ) {
423- removeLastHandle ( ) ;
424- return macro . EVENT_ABORT ;
434+ if ( anotherWidgetHasFocus ( ) ) {
435+ return macro . VOID ;
425436 }
426437
427438 const eventWithWidgetAction = {
@@ -451,7 +462,8 @@ export default function widgetBehavior(publicAPI: any, model: any) {
451462
452463 // Called after we are finished/placed.
453464 publicAPI . loseFocus = ( ) => {
454- if ( model . hasFocus ) {
465+ const hadFocus = model . hasFocus ;
466+ if ( hadFocus ) {
455467 model . _interactor . cancelAnimation ( publicAPI ) ;
456468 publicAPI . invokeEndInteractionEvent ( ) ;
457469 }
@@ -461,6 +473,14 @@ export default function widgetBehavior(publicAPI: any, model: any) {
461473 model . widgetState . getMoveHandle ( ) . setOrigin ( null ) ;
462474 model . activeState = null ;
463475 model . hasFocus = false ;
476+ if ( hadFocus ) {
477+ model . _widgetManager . releaseFocus ( ) ;
478+ // Deactivate all widgets so stale activeStates don't persist
479+ // (user may right-click again without moving mouse)
480+ model . _widgetManager
481+ . getWidgets ( )
482+ . forEach ( ( w : any ) => w . deactivateAllHandles ( ) ) ;
483+ }
464484 model . _widgetManager . enablePicking ( ) ;
465485 } ;
466486
0 commit comments