@@ -27,6 +27,7 @@ import * as eventUtils from './events/utils.js';
2727import type { Field } from './field.js' ;
2828import { getFocusManager } from './focus_manager.js' ;
2929import type { IBubble } from './interfaces/i_bubble.js' ;
30+ import { hasContextMenu } from './interfaces/i_contextmenu.js' ;
3031import { IDraggable , isDraggable } from './interfaces/i_draggable.js' ;
3132import { IDragger } from './interfaces/i_dragger.js' ;
3233import type { IFlyout } from './interfaces/i_flyout.js' ;
@@ -273,24 +274,19 @@ export class Gesture {
273274 throw new Error ( `Cannot update dragging from the flyout because the ' +
274275 'flyout's target workspace is undefined` ) ;
275276 }
276- if (
277- ! this . flyout . isScrollable ( ) ||
278- this . flyout . isDragTowardWorkspace ( this . currentDragDeltaXY )
279- ) {
280- this . startWorkspace_ = this . flyout . targetWorkspace ;
281- this . startWorkspace_ . updateScreenCalculationsIfScrolled ( ) ;
282- // Start the event group now, so that the same event group is used for
283- // block creation and block dragging.
284- if ( ! eventUtils . getGroup ( ) ) {
285- eventUtils . setGroup ( true ) ;
286- }
287- // The start block is no longer relevant, because this is a drag.
288- this . startBlock = null ;
289- this . targetBlock = this . flyout . createBlock ( this . targetBlock ) ;
290- getFocusManager ( ) . focusNode ( this . targetBlock ) ;
291- return true ;
277+
278+ this . startWorkspace_ = this . flyout . targetWorkspace ;
279+ this . startWorkspace_ . updateScreenCalculationsIfScrolled ( ) ;
280+ // Start the event group now, so that the same event group is used for
281+ // block creation and block dragging.
282+ if ( ! eventUtils . getGroup ( ) ) {
283+ eventUtils . setGroup ( true ) ;
292284 }
293- return false ;
285+ // The start block is no longer relevant, because this is a drag.
286+ this . startBlock = null ;
287+ this . targetBlock = this . flyout . createBlock ( this . targetBlock ) ;
288+ getFocusManager ( ) . focusNode ( this . targetBlock ) ;
289+ return true ;
294290 }
295291
296292 /**
@@ -732,22 +728,12 @@ export class Gesture {
732728 * @internal
733729 */
734730 handleRightClick ( e : PointerEvent ) {
735- if ( this . targetBlock ) {
736- this . bringBlockToFront ( ) ;
737- this . targetBlock . workspace . hideChaff ( ! ! this . flyout ) ;
738- this . targetBlock . showContextMenu ( e ) ;
739- } else if ( this . startBubble ) {
740- this . startBubble . showContextMenu ( e ) ;
741- } else if ( this . startComment ) {
742- this . startComment . workspace . hideChaff ( ) ;
743- this . startComment . showContextMenu ( e ) ;
744- } else if ( this . startWorkspace_ && ! this . flyout ) {
745- this . startWorkspace_ . hideChaff ( ) ;
746- getFocusManager ( ) . focusNode ( this . startWorkspace_ ) ;
747- this . startWorkspace_ . showContextMenu ( e ) ;
731+ const selection = getFocusManager ( ) . getFocusedNode ( ) ;
732+ if ( hasContextMenu ( selection ) ) {
733+ this . startWorkspace_ ?. hideChaff ( ! ! this . flyout ) ;
734+ selection . showContextMenu ( e ) ;
748735 }
749736
750- // TODO: Handle right-click on a bubble.
751737 e . preventDefault ( ) ;
752738 e . stopPropagation ( ) ;
753739
@@ -773,7 +759,12 @@ export class Gesture {
773759 this . setStartWorkspace ( ws ) ;
774760 this . mostRecentEvent = e ;
775761
776- if ( ! this . targetBlock && ! this . startBubble && ! this . startComment ) {
762+ if (
763+ ! this . targetBlock &&
764+ ! this . startBubble &&
765+ ! this . startComment &&
766+ ! this . startIcon
767+ ) {
777768 // Ensure the workspace is selected if nothing else should be. Note that
778769 // this is focusNode() instead of focusTree() because if any active node
779770 // is focused in the workspace it should be defocused.
@@ -878,12 +869,6 @@ export class Gesture {
878869 ) ;
879870 }
880871
881- // Note that the order is important here: bringing a block to the front will
882- // cause it to become focused and showing the field editor will capture
883- // focus ephemerally. It's important to ensure that focus is properly
884- // restored back to the block after field editing has completed.
885- this . bringBlockToFront ( ) ;
886-
887872 // Only show the editor if the field's editor wasn't already open
888873 // right before this gesture started.
889874 const dropdownAlreadyOpen = this . currentDropdownOwner === this . startField ;
@@ -899,7 +884,6 @@ export class Gesture {
899884 'Cannot do an icon click because the start icon is undefined' ,
900885 ) ;
901886 }
902- this . bringBlockToFront ( ) ;
903887 this . startIcon . onClick ( ) ;
904888 }
905889
@@ -938,7 +922,6 @@ export class Gesture {
938922 ) ;
939923 eventUtils . fire ( event ) ;
940924 }
941- this . bringBlockToFront ( ) ;
942925 eventUtils . setGroup ( false ) ;
943926 }
944927
@@ -957,19 +940,6 @@ export class Gesture {
957940
958941 // TODO (fenichel): Move bubbles to the front.
959942
960- /**
961- * Move the dragged/clicked block to the front of the workspace so that it is
962- * not occluded by other blocks.
963- */
964- private bringBlockToFront ( ) {
965- // Blocks in the flyout don't overlap, so skip the work.
966- if ( this . targetBlock && ! this . flyout ) {
967- // Always ensure the block being dragged/clicked has focus.
968- getFocusManager ( ) . focusNode ( this . targetBlock ) ;
969- this . targetBlock . bringToFront ( ) ;
970- }
971- }
972-
973943 /* Begin functions for populating a gesture at pointerdown. */
974944
975945 /**
@@ -1039,8 +1009,9 @@ export class Gesture {
10391009 * @internal
10401010 */
10411011 setStartBlock ( block : BlockSvg ) {
1042- // If the gesture already went through a bubble, don't set the start block.
1043- if ( ! this . startBlock && ! this . startBubble ) {
1012+ // If the gesture already went through a block child, don't set the start
1013+ // block.
1014+ if ( ! this . startBlock && ! this . startBubble && ! this . startIcon ) {
10441015 this . startBlock = block ;
10451016 if ( block . isInFlyout && block !== block . getRootBlock ( ) ) {
10461017 this . setTargetBlock ( block . getRootBlock ( ) ) ;
@@ -1064,7 +1035,8 @@ export class Gesture {
10641035 this . setTargetBlock ( block . getParent ( ) ! ) ;
10651036 } else {
10661037 this . targetBlock = block ;
1067- getFocusManager ( ) . focusNode ( block ) ;
1038+ getFocusManager ( ) . focusNode ( this . targetBlock ) ;
1039+ this . targetBlock . bringToFront ( ) ;
10681040 }
10691041 }
10701042
0 commit comments