-
Notifications
You must be signed in to change notification settings - Fork 3.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: support dragging comments in the gesture #7977
Merged
BeksOmega
merged 2 commits into
google:rc/v11.0.0
from
BeksOmega:feat/gesture-drag-comments
Apr 2, 2024
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,6 +37,7 @@ import type {IIcon} from './interfaces/i_icon.js'; | |
import {IDragger} from './interfaces/i_dragger.js'; | ||
import * as registry from './registry.js'; | ||
import {IDraggable} from './interfaces/i_draggable.js'; | ||
import {RenderedWorkspaceComment} from './comments.js'; | ||
|
||
/** | ||
* Note: In this file "start" refers to pointerdown | ||
|
@@ -85,6 +86,12 @@ export class Gesture { | |
*/ | ||
private startBlock: BlockSvg | null = null; | ||
|
||
/** | ||
* The comment that the gesture started on, or null if it did not start on a | ||
* comment. | ||
*/ | ||
private startComment: RenderedWorkspaceComment | null = null; | ||
|
||
/** | ||
* The block that this gesture targets. If the gesture started on a | ||
* shadow block, this is the first non-shadow parent of the block. If the | ||
|
@@ -315,6 +322,23 @@ export class Gesture { | |
return true; | ||
} | ||
|
||
/** | ||
* Update this gesture to record whether a comment is being dragged. | ||
* This function should be called on a pointermove event the first time | ||
* the drag radius is exceeded. It should be called no more than once per | ||
* gesture. | ||
* | ||
* @returns True if a comment is being dragged. | ||
*/ | ||
private updateIsDraggingComment(e: PointerEvent): boolean { | ||
if (!this.startComment) { | ||
return false; | ||
} | ||
|
||
this.startDraggingComment(e); | ||
return true; | ||
} | ||
|
||
/** | ||
* Check whether to start a block drag. If a block should be dragged, either | ||
* from the flyout or in the workspace, create the necessary BlockDragger and | ||
|
@@ -394,19 +418,22 @@ export class Gesture { | |
if (this.updateIsDraggingBlock(e)) { | ||
return; | ||
} | ||
if (this.updateIsDraggingComment(e)) { | ||
return; | ||
} | ||
// Then check if it's a workspace drag. | ||
this.updateIsDraggingWorkspace(); | ||
} | ||
|
||
/** Create a block dragger and start dragging the selected block. */ | ||
/** Start dragging the selected block. */ | ||
private startDraggingBlock(e: PointerEvent) { | ||
this.dragging = true; | ||
this.dragger = this.createDragger(this.targetBlock!, this.startWorkspace_!); | ||
this.dragger.onDragStart(e); | ||
this.dragger.onDrag(e, this.currentDragDeltaXY); | ||
} | ||
|
||
/** Create a bubble dragger and start dragging the selected bubble. */ | ||
/** Start dragging the selected bubble. */ | ||
private startDraggingBubble(e: PointerEvent) { | ||
if (!this.startBubble) { | ||
throw new Error( | ||
|
@@ -427,6 +454,27 @@ export class Gesture { | |
this.dragger.onDrag(e, this.currentDragDeltaXY); | ||
} | ||
|
||
/** Start dragging the selected bubble. */ | ||
private startDraggingComment(e: PointerEvent) { | ||
if (!this.startComment) { | ||
throw new Error( | ||
'Cannot update dragging the comment because the start ' + | ||
'comment is undefined', | ||
); | ||
} | ||
if (!this.startWorkspace_) { | ||
throw new Error( | ||
'Cannot update dragging the bubble because the start ' + | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. bubble -> comment |
||
'workspace is undefined', | ||
); | ||
} | ||
|
||
this.dragging = true; | ||
this.dragger = this.createDragger(this.startComment, this.startWorkspace_); | ||
this.dragger.onDragStart(e); | ||
this.dragger.onDrag(e, this.currentDragDeltaXY); | ||
} | ||
|
||
private createDragger( | ||
draggable: IDraggable, | ||
workspace: WorkspaceSvg, | ||
|
@@ -893,6 +941,24 @@ export class Gesture { | |
this.mostRecentEvent = e; | ||
} | ||
|
||
/** | ||
* Handle a pointerdown event on a workspace comment. | ||
* | ||
* @param e A pointerdown event. | ||
* @param comment The comment the event hit. | ||
* @internal | ||
*/ | ||
handleCommentStart(e: PointerEvent, comment: RenderedWorkspaceComment) { | ||
if (this.gestureHasStarted) { | ||
throw Error( | ||
'Tried to call gesture.handleBubbleStart, ' + | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. handleBubbleStart -> handleCommentStart |
||
'but the gesture had already been started.', | ||
); | ||
} | ||
this.setStartComment(comment); | ||
this.mostRecentEvent = e; | ||
} | ||
|
||
/* Begin functions defining what actions to take to execute clicks on each | ||
* type of target. Any developer wanting to add behaviour on clicks should | ||
* modify only this code. */ | ||
|
@@ -1049,6 +1115,18 @@ export class Gesture { | |
} | ||
} | ||
|
||
/** | ||
* Record the comment that a gesture started on | ||
* | ||
* @param comment The comment the gesture started on. | ||
* @internal | ||
*/ | ||
setStartComment(comment: RenderedWorkspaceComment) { | ||
if (!this.startComment) { | ||
this.startComment = comment; | ||
} | ||
} | ||
|
||
/** | ||
* Record the block that a gesture started on, and set the target block | ||
* appropriately. | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bubble -> comment