Skip to content

Commit 2ee18d4

Browse files
committed
feat: Allow calling WorkspaceSvg.getGesture() without passing an event
1 parent 2debc4b commit 2ee18d4

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

packages/blockly/core/workspace_svg.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2467,17 +2467,17 @@ export class WorkspaceSvg
24672467
* valid gesture exists.
24682468
* @internal
24692469
*/
2470-
getGesture(e: PointerEvent): Gesture | null {
2470+
getGesture(e?: PointerEvent): Gesture | null {
24712471
// TODO(#8960): Query Mover.isMoving to see if move is in progress
24722472
// rather than relying on .keyboardMoveInProgress status flag.
24732473
if (this.keyboardMoveInProgress) {
24742474
// Normally these would be called from Gesture.doStart.
2475-
e.preventDefault();
2476-
e.stopPropagation();
2475+
e?.preventDefault();
2476+
e?.stopPropagation();
24772477
return null;
24782478
}
24792479

2480-
const isStart = e.type === 'pointerdown';
2480+
const isStart = e?.type === 'pointerdown';
24812481
if (isStart && this.currentGesture_?.hasStarted()) {
24822482
console.warn('Tried to start the same gesture twice.');
24832483
// That's funny. We must have missed a mouse up.

packages/blockly/tests/mocha/workspace_svg_test.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
sharedTestSetup,
1717
sharedTestTeardown,
1818
} from './test_helpers/setup_teardown.js';
19+
import {dispatchPointerEvent} from './test_helpers/user_input.js';
1920
import {testAWorkspace} from './test_helpers/workspace.js';
2021

2122
suite('WorkspaceSvg', function () {
@@ -114,6 +115,17 @@ suite('WorkspaceSvg', function () {
114115
assert.equal(true, shadowBlock.isDeadOrDying());
115116
});
116117

118+
test('getGesture returns null when no gesture is in progress', function () {
119+
const gesture = this.workspace.getGesture();
120+
assert.isNull(gesture);
121+
});
122+
123+
test('getGesture returns the current gesture when one is in progress', function () {
124+
dispatchPointerEvent(this.workspace.getSvgGroup(), 'pointerdown');
125+
const gesture = this.workspace.getGesture();
126+
assert.isNotNull(gesture);
127+
});
128+
117129
suite('updateToolbox', function () {
118130
test('Passes in null when toolbox exists', function () {
119131
assert.throws(

0 commit comments

Comments
 (0)