From 2ee18d4d6f877e7914323277128be5a93479c466 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Mon, 26 Jan 2026 10:08:53 +0000 Subject: [PATCH] feat: Allow calling `WorkspaceSvg.getGesture()` without passing an event --- packages/blockly/core/workspace_svg.ts | 8 ++++---- packages/blockly/tests/mocha/workspace_svg_test.js | 12 ++++++++++++ 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/packages/blockly/core/workspace_svg.ts b/packages/blockly/core/workspace_svg.ts index de158c6d426..c693225970f 100644 --- a/packages/blockly/core/workspace_svg.ts +++ b/packages/blockly/core/workspace_svg.ts @@ -2467,17 +2467,17 @@ export class WorkspaceSvg * valid gesture exists. * @internal */ - getGesture(e: PointerEvent): Gesture | null { + getGesture(e?: PointerEvent): Gesture | null { // TODO(#8960): Query Mover.isMoving to see if move is in progress // rather than relying on .keyboardMoveInProgress status flag. if (this.keyboardMoveInProgress) { // Normally these would be called from Gesture.doStart. - e.preventDefault(); - e.stopPropagation(); + e?.preventDefault(); + e?.stopPropagation(); return null; } - const isStart = e.type === 'pointerdown'; + const isStart = e?.type === 'pointerdown'; if (isStart && this.currentGesture_?.hasStarted()) { console.warn('Tried to start the same gesture twice.'); // That's funny. We must have missed a mouse up. diff --git a/packages/blockly/tests/mocha/workspace_svg_test.js b/packages/blockly/tests/mocha/workspace_svg_test.js index 6193dda2db7..b40a46941bd 100644 --- a/packages/blockly/tests/mocha/workspace_svg_test.js +++ b/packages/blockly/tests/mocha/workspace_svg_test.js @@ -16,6 +16,7 @@ import { sharedTestSetup, sharedTestTeardown, } from './test_helpers/setup_teardown.js'; +import {dispatchPointerEvent} from './test_helpers/user_input.js'; import {testAWorkspace} from './test_helpers/workspace.js'; suite('WorkspaceSvg', function () { @@ -114,6 +115,17 @@ suite('WorkspaceSvg', function () { assert.equal(true, shadowBlock.isDeadOrDying()); }); + test('getGesture returns null when no gesture is in progress', function () { + const gesture = this.workspace.getGesture(); + assert.isNull(gesture); + }); + + test('getGesture returns the current gesture when one is in progress', function () { + dispatchPointerEvent(this.workspace.getSvgGroup(), 'pointerdown'); + const gesture = this.workspace.getGesture(); + assert.isNotNull(gesture); + }); + suite('updateToolbox', function () { test('Passes in null when toolbox exists', function () { assert.throws(