From 504de6a98c741c902a00d6534eb69f7c31e45b9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=84=8D=F0=9D=95=A0=F0=9D=95=9D=F0=9D=95=9D=F0=9D=95=A0?= =?UTF-8?q?=F0=9D=95=A8=20=F0=9D=95=84=F0=9D=95=92=F0=9D=95=9F?= Date: Fri, 26 Jul 2024 00:09:10 +0300 Subject: [PATCH] fix: drag strategy only clear group id set by us (#8355) Add a condition check so that we don't unset the group ID that is not set by us. Otherwise the multi-select plugin undo/redo will be broken (apply individually instead of all together) Signed-off-by: Hollow Man --- core/dragging/block_drag_strategy.ts | 10 ++++++++-- core/dragging/bubble_drag_strategy.ts | 10 ++++++++-- core/dragging/comment_drag_strategy.ts | 10 ++++++++-- 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/core/dragging/block_drag_strategy.ts b/core/dragging/block_drag_strategy.ts index dc136d814..2afdba51f 100644 --- a/core/dragging/block_drag_strategy.ts +++ b/core/dragging/block_drag_strategy.ts @@ -61,6 +61,9 @@ export class BlockDragStrategy implements IDragStrategy { */ private dragOffset = new Coordinate(0, 0); + /** Was there already an event group in progress when the drag started? */ + private inGroup: boolean = false; + constructor(private block: BlockSvg) { this.workspace = block.workspace; } @@ -92,7 +95,8 @@ export class BlockDragStrategy implements IDragStrategy { } this.dragging = true; - if (!eventUtils.getGroup()) { + this.inGroup = !!eventUtils.getGroup(); + if (!this.inGroup) { eventUtils.setGroup(true); } this.fireDragStartEvent(); @@ -389,7 +393,9 @@ export class BlockDragStrategy implements IDragStrategy { this.connectionPreviewer!.dispose(); this.workspace.setResizesEnabled(true); - eventUtils.setGroup(false); + if (!this.inGroup) { + eventUtils.setGroup(false); + } } /** Connects the given candidate connections. */ diff --git a/core/dragging/bubble_drag_strategy.ts b/core/dragging/bubble_drag_strategy.ts index 7ffccddc1..f388bb94c 100644 --- a/core/dragging/bubble_drag_strategy.ts +++ b/core/dragging/bubble_drag_strategy.ts @@ -13,6 +13,9 @@ import * as layers from '../layers.js'; export class BubbleDragStrategy implements IDragStrategy { private startLoc: Coordinate | null = null; + /** Was there already an event group in progress when the drag started? */ + private inGroup: boolean = false; + constructor( private bubble: IBubble, private workspace: WorkspaceSvg, @@ -23,7 +26,8 @@ export class BubbleDragStrategy implements IDragStrategy { } startDrag(): void { - if (!eventUtils.getGroup()) { + this.inGroup = !!eventUtils.getGroup(); + if (!this.inGroup) { eventUtils.setGroup(true); } this.startLoc = this.bubble.getRelativeToSurfaceXY(); @@ -38,7 +42,9 @@ export class BubbleDragStrategy implements IDragStrategy { endDrag(): void { this.workspace.setResizesEnabled(true); - eventUtils.setGroup(false); + if (!this.inGroup) { + eventUtils.setGroup(false); + } this.workspace .getLayerManager() diff --git a/core/dragging/comment_drag_strategy.ts b/core/dragging/comment_drag_strategy.ts index 2ad5fa144..2197d37f2 100644 --- a/core/dragging/comment_drag_strategy.ts +++ b/core/dragging/comment_drag_strategy.ts @@ -17,6 +17,9 @@ export class CommentDragStrategy implements IDragStrategy { private workspace: WorkspaceSvg; + /** Was there already an event group in progress when the drag started? */ + private inGroup: boolean = false; + constructor(private comment: RenderedWorkspaceComment) { this.workspace = comment.workspace; } @@ -26,7 +29,8 @@ export class CommentDragStrategy implements IDragStrategy { } startDrag(): void { - if (!eventUtils.getGroup()) { + this.inGroup = !!eventUtils.getGroup(); + if (!this.inGroup) { eventUtils.setGroup(true); } this.fireDragStartEvent(); @@ -52,7 +56,9 @@ export class CommentDragStrategy implements IDragStrategy { this.comment.snapToGrid(); this.workspace.setResizesEnabled(true); - eventUtils.setGroup(false); + if (!this.inGroup) { + eventUtils.setGroup(false); + } } /** Fire a UI event at the start of a comment drag. */