Files
blockly/core/dragging/bubble_drag_strategy.ts
ℍ𝕠𝕝𝕝𝕠𝕨 𝕄𝕒𝕟 504de6a98c 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 <hollowman@opensuse.org>
2024-07-25 22:09:10 +01:00

59 lines
1.5 KiB
TypeScript

/**
* @license
* Copyright 2024 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
import {IDragStrategy} from '../interfaces/i_draggable.js';
import {Coordinate} from '../utils.js';
import * as eventUtils from '../events/utils.js';
import {IBubble, WorkspaceSvg} from '../blockly.js';
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,
) {}
isMovable(): boolean {
return true;
}
startDrag(): void {
this.inGroup = !!eventUtils.getGroup();
if (!this.inGroup) {
eventUtils.setGroup(true);
}
this.startLoc = this.bubble.getRelativeToSurfaceXY();
this.workspace.setResizesEnabled(false);
this.workspace.getLayerManager()?.moveToDragLayer(this.bubble);
this.bubble.setDragging && this.bubble.setDragging(true);
}
drag(newLoc: Coordinate): void {
this.bubble.moveDuringDrag(newLoc);
}
endDrag(): void {
this.workspace.setResizesEnabled(true);
if (!this.inGroup) {
eventUtils.setGroup(false);
}
this.workspace
.getLayerManager()
?.moveOffDragLayer(this.bubble, layers.BUBBLE);
this.bubble.setDragging(false);
}
revertDrag(): void {
if (this.startLoc) this.bubble.moveDuringDrag(this.startLoc);
}
}