From a865744b7e3be43ce460d3a73d15edf2f3d4f266 Mon Sep 17 00:00:00 2001 From: Beka Westberg Date: Wed, 17 Apr 2024 21:02:46 +0000 Subject: [PATCH] fix: bumping comments into bounds (#8037) --- core/bump_objects.ts | 7 +++---- core/dragging/comment_drag_strategy.ts | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/core/bump_objects.ts b/core/bump_objects.ts index d06b66800..7085f78d5 100644 --- a/core/bump_objects.ts +++ b/core/bump_objects.ts @@ -6,7 +6,7 @@ // Former goog.module ID: Blockly.bumpObjects -import type {BlockSvg} from './block_svg.js'; +import {RenderedWorkspaceComment} from './comments.js'; import type {Abstract} from './events/events_abstract.js'; import type {BlockCreate} from './events/events_block_create.js'; import type {BlockMove} from './events/events_block_move.js'; @@ -17,7 +17,6 @@ import * as eventUtils from './events/utils.js'; import type {IBoundedElement} from './interfaces/i_bounded_element.js'; import type {ContainerRegion} from './metrics_manager.js'; import * as mathUtils from './utils/math.js'; -import type {WorkspaceCommentSvg} from './workspace_comment_svg.js'; import type {WorkspaceSvg} from './workspace_svg.js'; /** @@ -152,7 +151,7 @@ export function bumpIntoBoundsHandler( function extractObjectFromEvent( workspace: WorkspaceSvg, e: eventUtils.BumpEvent, -): BlockSvg | null | WorkspaceCommentSvg { +): IBoundedElement | null { let object = null; switch (e.type) { case eventUtils.BLOCK_CREATE: @@ -166,7 +165,7 @@ function extractObjectFromEvent( case eventUtils.COMMENT_MOVE: object = workspace.getCommentById( (e as CommentCreate | CommentMove).commentId!, - ) as WorkspaceCommentSvg | null; + ) as AnyDuringMigration as RenderedWorkspaceComment; break; } return object; diff --git a/core/dragging/comment_drag_strategy.ts b/core/dragging/comment_drag_strategy.ts index f030e1488..5fe5e356c 100644 --- a/core/dragging/comment_drag_strategy.ts +++ b/core/dragging/comment_drag_strategy.ts @@ -10,6 +10,7 @@ import * as eventUtils from '../events/utils.js'; import * as layers from '../layers.js'; import {RenderedWorkspaceComment} from '../comments.js'; import {WorkspaceSvg} from '../workspace_svg.js'; +import {CommentMove} from '../events/events_comment_move.js'; export class CommentDragStrategy implements IDragStrategy { private startLoc: Coordinate | null = null; @@ -39,6 +40,8 @@ export class CommentDragStrategy implements IDragStrategy { } endDrag(): void { + this.fireMoveEvent(); + this.workspace.setResizesEnabled(true); eventUtils.setGroup(false); @@ -48,6 +51,17 @@ export class CommentDragStrategy implements IDragStrategy { this.comment.setDragging(false); } + private fireMoveEvent() { + if (this.comment.isDeadOrDying()) return; + const event = new (eventUtils.get(eventUtils.COMMENT_MOVE))( + this.comment, + ) as CommentMove; + event.setReason(['drag']); + event.oldCoordinate_ = this.startLoc!; + event.recordNew(); + eventUtils.fire(event); + } + revertDrag(): void { if (this.startLoc) this.comment.moveDuringDrag(this.startLoc); }