Merge pull request #9583 from RaspberryPiFoundation/get-gesture

feat: Allow calling `WorkspaceSvg.getGesture()` without passing an event
This commit is contained in:
Aaron Dodson
2026-01-27 00:53:47 -08:00
committed by GitHub
2 changed files with 16 additions and 4 deletions

View File

@@ -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.

View File

@@ -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(