@@ -37,6 +37,7 @@ import type {IIcon} from './interfaces/i_icon.js';
3737import { IDragger } from './interfaces/i_dragger.js' ;
3838import * as registry from './registry.js' ;
3939import { IDraggable } from './interfaces/i_draggable.js' ;
40+ import { RenderedWorkspaceComment } from './comments.js' ;
4041
4142/**
4243 * Note: In this file "start" refers to pointerdown
@@ -85,6 +86,12 @@ export class Gesture {
8586 */
8687 private startBlock : BlockSvg | null = null ;
8788
89+ /**
90+ * The comment that the gesture started on, or null if it did not start on a
91+ * comment.
92+ */
93+ private startComment : RenderedWorkspaceComment | null = null ;
94+
8895 /**
8996 * The block that this gesture targets. If the gesture started on a
9097 * shadow block, this is the first non-shadow parent of the block. If the
@@ -315,6 +322,23 @@ export class Gesture {
315322 return true ;
316323 }
317324
325+ /**
326+ * Update this gesture to record whether a comment is being dragged.
327+ * This function should be called on a pointermove event the first time
328+ * the drag radius is exceeded. It should be called no more than once per
329+ * gesture.
330+ *
331+ * @returns True if a comment is being dragged.
332+ */
333+ private updateIsDraggingComment ( e : PointerEvent ) : boolean {
334+ if ( ! this . startComment ) {
335+ return false ;
336+ }
337+
338+ this . startDraggingComment ( e ) ;
339+ return true ;
340+ }
341+
318342 /**
319343 * Check whether to start a block drag. If a block should be dragged, either
320344 * from the flyout or in the workspace, create the necessary BlockDragger and
@@ -394,19 +418,22 @@ export class Gesture {
394418 if ( this . updateIsDraggingBlock ( e ) ) {
395419 return ;
396420 }
421+ if ( this . updateIsDraggingComment ( e ) ) {
422+ return ;
423+ }
397424 // Then check if it's a workspace drag.
398425 this . updateIsDraggingWorkspace ( ) ;
399426 }
400427
401- /** Create a block dragger and start dragging the selected block. */
428+ /** Start dragging the selected block. */
402429 private startDraggingBlock ( e : PointerEvent ) {
403430 this . dragging = true ;
404431 this . dragger = this . createDragger ( this . targetBlock ! , this . startWorkspace_ ! ) ;
405432 this . dragger . onDragStart ( e ) ;
406433 this . dragger . onDrag ( e , this . currentDragDeltaXY ) ;
407434 }
408435
409- /** Create a bubble dragger and start dragging the selected bubble. */
436+ /** Start dragging the selected bubble. */
410437 private startDraggingBubble ( e : PointerEvent ) {
411438 if ( ! this . startBubble ) {
412439 throw new Error (
@@ -427,6 +454,27 @@ export class Gesture {
427454 this . dragger . onDrag ( e , this . currentDragDeltaXY ) ;
428455 }
429456
457+ /** Start dragging the selected comment. */
458+ private startDraggingComment ( e : PointerEvent ) {
459+ if ( ! this . startComment ) {
460+ throw new Error (
461+ 'Cannot update dragging the comment because the start ' +
462+ 'comment is undefined' ,
463+ ) ;
464+ }
465+ if ( ! this . startWorkspace_ ) {
466+ throw new Error (
467+ 'Cannot update dragging the comment because the start ' +
468+ 'workspace is undefined' ,
469+ ) ;
470+ }
471+
472+ this . dragging = true ;
473+ this . dragger = this . createDragger ( this . startComment , this . startWorkspace_ ) ;
474+ this . dragger . onDragStart ( e ) ;
475+ this . dragger . onDrag ( e , this . currentDragDeltaXY ) ;
476+ }
477+
430478 private createDragger (
431479 draggable : IDraggable ,
432480 workspace : WorkspaceSvg ,
@@ -893,6 +941,24 @@ export class Gesture {
893941 this . mostRecentEvent = e ;
894942 }
895943
944+ /**
945+ * Handle a pointerdown event on a workspace comment.
946+ *
947+ * @param e A pointerdown event.
948+ * @param comment The comment the event hit.
949+ * @internal
950+ */
951+ handleCommentStart ( e : PointerEvent , comment : RenderedWorkspaceComment ) {
952+ if ( this . gestureHasStarted ) {
953+ throw Error (
954+ 'Tried to call gesture.handleCommentStart, ' +
955+ 'but the gesture had already been started.' ,
956+ ) ;
957+ }
958+ this . setStartComment ( comment ) ;
959+ this . mostRecentEvent = e ;
960+ }
961+
896962 /* Begin functions defining what actions to take to execute clicks on each
897963 * type of target. Any developer wanting to add behaviour on clicks should
898964 * modify only this code. */
@@ -1049,6 +1115,18 @@ export class Gesture {
10491115 }
10501116 }
10511117
1118+ /**
1119+ * Record the comment that a gesture started on
1120+ *
1121+ * @param comment The comment the gesture started on.
1122+ * @internal
1123+ */
1124+ setStartComment ( comment : RenderedWorkspaceComment ) {
1125+ if ( ! this . startComment ) {
1126+ this . startComment = comment ;
1127+ }
1128+ }
1129+
10521130 /**
10531131 * Record the block that a gesture started on, and set the target block
10541132 * appropriately.
0 commit comments