Skip to content

Commit bc0e1c3

Browse files
authored
feat(WorkspaceSvg): Ignore gestures when keyboard move in progress (#8963)
* feat(WorkspaceSvg): Ignore gestures during keyboard moves Modify WorkspaceSvg.prototype.getGesture to return null when there is a keyboard-initiated move in progress. * chore(WorkspaceSvg): Add TODOs to remove .keyboardMoveInProgress
1 parent a4e6166 commit bc0e1c3

File tree

1 file changed

+35
-20
lines changed

1 file changed

+35
-20
lines changed

core/workspace_svg.ts

Lines changed: 35 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ export class WorkspaceSvg
314314
keyboardAccessibilityMode = false;
315315

316316
/** True iff a keyboard-initiated move ("drag") is in progress. */
317-
keyboardMoveInProgress = false;
317+
keyboardMoveInProgress = false; // TODO(#8960): Delete this.
318318

319319
/** The list of top-level bounded elements on the workspace. */
320320
private topBoundedElements: IBoundedElement[] = [];
@@ -1471,6 +1471,8 @@ export class WorkspaceSvg
14711471
* removed, at an time without notice and without being treated
14721472
* as a breaking change.
14731473
*
1474+
* TODO(#8960): Delete this.
1475+
*
14741476
* @internal
14751477
* @param inProgress Is a keyboard-initated move in progress?
14761478
*/
@@ -1494,6 +1496,8 @@ export class WorkspaceSvg
14941496
*/
14951497
isDragging(): boolean {
14961498
return (
1499+
// TODO(#8960): Query Mover.isMoving to see if move is in
1500+
// progress rather than relying on a status flag.
14971501
this.keyboardMoveInProgress ||
14981502
(this.currentGesture_ !== null && this.currentGesture_.isDragging())
14991503
);
@@ -2403,36 +2407,47 @@ export class WorkspaceSvg
24032407

24042408
/**
24052409
* Look up the gesture that is tracking this touch stream on this workspace.
2406-
* May create a new gesture.
2410+
*
2411+
* Returns the gesture in progress, except:
2412+
*
2413+
* - If there is a keyboard-initiate move in progress then null will
2414+
* be returned - after calling event.preventDefault() and
2415+
* event.stopPropagation() to ensure the pointer event is ignored.
2416+
* - If there is a gesture in progress but event.type is
2417+
* 'pointerdown' then the in-progress gesture will be cancelled;
2418+
* this will result in null being returned.
2419+
* - If no gesutre is in progress but event is a pointerdown then a
2420+
* new gesture will be created and returned.
24072421
*
24082422
* @param e Pointer event.
24092423
* @returns The gesture that is tracking this touch stream, or null if no
24102424
* valid gesture exists.
24112425
* @internal
24122426
*/
24132427
getGesture(e: PointerEvent): Gesture | null {
2414-
const isStart = e.type === 'pointerdown';
2415-
2416-
const gesture = this.currentGesture_;
2417-
if (gesture) {
2418-
if (isStart && gesture.hasStarted()) {
2419-
console.warn('Tried to start the same gesture twice.');
2420-
// That's funny. We must have missed a mouse up.
2421-
// Cancel it, rather than try to retrieve all of the state we need.
2422-
gesture.cancel();
2423-
return null;
2424-
}
2425-
return gesture;
2428+
// TODO(#8960): Query Mover.isMoving to see if move is in progress
2429+
// rather than relying on .keyboardMoveInProgress status flag.
2430+
if (this.keyboardMoveInProgress) {
2431+
// Normally these would be called from Gesture.doStart.
2432+
e.preventDefault();
2433+
e.stopPropagation();
2434+
return null;
24262435
}
24272436

2428-
// No gesture existed on this workspace, but this looks like the start of a
2429-
// new gesture.
2430-
if (isStart) {
2437+
const isStart = e.type === 'pointerdown';
2438+
if (isStart && this.currentGesture_?.hasStarted()) {
2439+
console.warn('Tried to start the same gesture twice.');
2440+
// That's funny. We must have missed a mouse up.
2441+
// Cancel it, rather than try to retrieve all of the state we need.
2442+
this.currentGesture_.cancel(); // Sets this.currentGesture_ to null.
2443+
}
2444+
if (!this.currentGesture_ && isStart) {
2445+
// No gesture existed on this workspace, but this looks like the
2446+
// start of a new gesture.
24312447
this.currentGesture_ = new Gesture(e, this);
2432-
return this.currentGesture_;
24332448
}
2434-
// No gesture existed and this event couldn't be the start of a new gesture.
2435-
return null;
2449+
2450+
return this.currentGesture_;
24362451
}
24372452

24382453
/**

0 commit comments

Comments
 (0)