Skip to content

Commit ffdcd5c

Browse files
feat: unpack direction info in keyboard drag strategy
1 parent c122d53 commit ffdcd5c

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

src/keyboard_drag_strategy.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,33 @@
44
* SPDX-License-Identifier: Apache-2.0
55
*/
66

7-
import {dragging} from 'blockly';
7+
import {dragging, utils} from 'blockly';
8+
import {Direction, getDirectionFromXY} from './drag_direction';
89

910
export class KeyboardDragStrategy extends dragging.BlockDragStrategy {
11+
private currentDragDirection: Direction | null = null;
12+
1013
override startDrag(e?: PointerEvent) {
1114
super.startDrag(e);
1215
// Set position of the dragging block, so that it doesn't pop
1316
// to the top left of the workspace.
1417
// @ts-expect-error block and startLoc are private.
1518
this.block.moveDuringDrag(this.startLoc);
1619
}
20+
21+
override drag(newLoc: utils.Coordinate, e?: PointerEvent): void {
22+
if (!e) return;
23+
this.currentDragDirection = getDirectionFromXY({x: e.tiltX, y: e.tiltY});
24+
super.drag(newLoc);
25+
}
26+
27+
/**
28+
* Get whether the most recent drag event represents a constrained
29+
* keyboard drag.
30+
*
31+
* @returns true if the current movement is constrained, otherwise false.
32+
*/
33+
private isConstrainedMovement(): boolean {
34+
return !!this.currentDragDirection;
35+
}
1736
}

0 commit comments

Comments
 (0)