mirror of
https://github.com/google/blockly.git
synced 2026-01-07 00:50:27 +01:00
fix: bumping comments into bounds (#8037)
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user