mirror of
https://github.com/google/blockly.git
synced 2026-02-12 18:40:10 +01:00
Merge pull request #9583 from RaspberryPiFoundation/get-gesture
feat: Allow calling `WorkspaceSvg.getGesture()` without passing an event
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user