Skip to content

Commit b343a13

Browse files
authored
fix: Fixes #8764 by moving the event grouping calls up to dragger.ts (#8781)
1 parent 8c25c1f commit b343a13

4 files changed

Lines changed: 13 additions & 35 deletions

File tree

core/dragging/block_drag_strategy.ts

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ export class BlockDragStrategy implements IDragStrategy {
6262
*/
6363
private dragOffset = new Coordinate(0, 0);
6464

65-
/** Was there already an event group in progress when the drag started? */
66-
private inGroup: boolean = false;
65+
/** Used to persist an event group when snapping is done async. */
66+
private originalEventGroup = '';
6767

6868
constructor(private block: BlockSvg) {
6969
this.workspace = block.workspace;
@@ -96,10 +96,6 @@ export class BlockDragStrategy implements IDragStrategy {
9696
}
9797

9898
this.dragging = true;
99-
this.inGroup = !!eventUtils.getGroup();
100-
if (!this.inGroup) {
101-
eventUtils.setGroup(true);
102-
}
10399
this.fireDragStartEvent();
104100

105101
this.startLoc = this.block.getRelativeToSurfaceXY();
@@ -363,6 +359,7 @@ export class BlockDragStrategy implements IDragStrategy {
363359
this.block.getParent()?.endDrag(e);
364360
return;
365361
}
362+
this.originalEventGroup = eventUtils.getGroup();
366363

367364
this.fireDragEndEvent();
368365
this.fireMoveEvent();
@@ -388,20 +385,19 @@ export class BlockDragStrategy implements IDragStrategy {
388385
} else {
389386
this.block.queueRender().then(() => this.disposeStep());
390387
}
391-
392-
if (!this.inGroup) {
393-
eventUtils.setGroup(false);
394-
}
395388
}
396389

397390
/** Disposes of any state at the end of the drag. */
398391
private disposeStep() {
392+
const newGroup = eventUtils.getGroup();
393+
eventUtils.setGroup(this.originalEventGroup);
399394
this.block.snapToGrid();
400395

401396
// Must dispose after connections are applied to not break the dynamic
402397
// connections plugin. See #7859
403398
this.connectionPreviewer!.dispose();
404399
this.workspace.setResizesEnabled(true);
400+
eventUtils.setGroup(newGroup);
405401
}
406402

407403
/** Connects the given candidate connections. */

core/dragging/bubble_drag_strategy.ts

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,13 @@
55
*/
66

77
import {IBubble, WorkspaceSvg} from '../blockly.js';
8-
import * as eventUtils from '../events/utils.js';
98
import {IDragStrategy} from '../interfaces/i_draggable.js';
109
import * as layers from '../layers.js';
1110
import {Coordinate} from '../utils.js';
1211

1312
export class BubbleDragStrategy implements IDragStrategy {
1413
private startLoc: Coordinate | null = null;
1514

16-
/** Was there already an event group in progress when the drag started? */
17-
private inGroup: boolean = false;
18-
1915
constructor(
2016
private bubble: IBubble,
2117
private workspace: WorkspaceSvg,
@@ -26,10 +22,6 @@ export class BubbleDragStrategy implements IDragStrategy {
2622
}
2723

2824
startDrag(): void {
29-
this.inGroup = !!eventUtils.getGroup();
30-
if (!this.inGroup) {
31-
eventUtils.setGroup(true);
32-
}
3325
this.startLoc = this.bubble.getRelativeToSurfaceXY();
3426
this.workspace.setResizesEnabled(false);
3527
this.workspace.getLayerManager()?.moveToDragLayer(this.bubble);
@@ -44,9 +36,6 @@ export class BubbleDragStrategy implements IDragStrategy {
4436

4537
endDrag(): void {
4638
this.workspace.setResizesEnabled(true);
47-
if (!this.inGroup) {
48-
eventUtils.setGroup(false);
49-
}
5039

5140
this.workspace
5241
.getLayerManager()

core/dragging/comment_drag_strategy.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@ export class CommentDragStrategy implements IDragStrategy {
1818

1919
private workspace: WorkspaceSvg;
2020

21-
/** Was there already an event group in progress when the drag started? */
22-
private inGroup: boolean = false;
23-
2421
constructor(private comment: RenderedWorkspaceComment) {
2522
this.workspace = comment.workspace;
2623
}
@@ -34,10 +31,6 @@ export class CommentDragStrategy implements IDragStrategy {
3431
}
3532

3633
startDrag(): void {
37-
this.inGroup = !!eventUtils.getGroup();
38-
if (!this.inGroup) {
39-
eventUtils.setGroup(true);
40-
}
4134
this.fireDragStartEvent();
4235
this.startLoc = this.comment.getRelativeToSurfaceXY();
4336
this.workspace.setResizesEnabled(false);
@@ -61,9 +54,6 @@ export class CommentDragStrategy implements IDragStrategy {
6154
this.comment.snapToGrid();
6255

6356
this.workspace.setResizesEnabled(true);
64-
if (!this.inGroup) {
65-
eventUtils.setGroup(false);
66-
}
6757
}
6858

6959
/** Fire a UI event at the start of a comment drag. */

core/dragging/dragger.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ export class Dragger implements IDragger {
3131

3232
/** Handles any drag startup. */
3333
onDragStart(e: PointerEvent) {
34+
if (!eventUtils.getGroup()) {
35+
eventUtils.setGroup(true);
36+
}
3437
this.draggable.startDrag(e);
3538
}
3639

@@ -119,13 +122,13 @@ export class Dragger implements IDragger {
119122
this.draggable.endDrag(e);
120123

121124
if (wouldDelete && isDeletable(root)) {
122-
// We want to make sure the delete gets grouped with any possible
123-
// move event.
124-
const newGroup = eventUtils.getGroup();
125+
// We want to make sure the delete gets grouped with any possible move
126+
// event. In core Blockly this shouldn't happen, but due to a change
127+
// in behavior older custom draggables might still clear the group.
125128
eventUtils.setGroup(origGroup);
126129
root.dispose();
127-
eventUtils.setGroup(newGroup);
128130
}
131+
eventUtils.setGroup(false);
129132
}
130133

131134
// We need to special case blocks for now so that we look at the root block

0 commit comments

Comments
 (0)