Skip to content

Commit 121a15a

Browse files
committed
fix: preserve multi-touch recording semantics
1 parent cd9f74f commit 121a15a

3 files changed

Lines changed: 51 additions & 11 deletions

File tree

src/daemon/__tests__/recording-gestures.test.ts

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -314,37 +314,63 @@ test('canonical rotate records centroid visualization telemetry', () => {
314314
]);
315315
});
316316

317-
test('canonical transform records centroid travel visualization telemetry', () => {
317+
test('canonical multi-touch travel does not acquire one-finger back-swipe semantics', () => {
318318
const session = makeSession();
319319

320320
recordTouchVisualizationEvent(
321321
session,
322322
'gesture',
323-
['transform', '201', '437', '40', '-30', '1.4', '25', '600'],
323+
['transform', '10', '437', '170', '0', '1.4', '25', '600'],
324324
{
325325
kind: 'transform',
326-
from: { x: 201, y: 437 },
327-
to: { x: 241, y: 407 },
326+
from: { x: 10, y: 437 },
327+
to: { x: 180, y: 437 },
328328
durationMs: 600,
329329
pointerCount: 2,
330330
},
331331
{},
332332
1_500,
333333
2_100,
334334
);
335+
recordTouchVisualizationEvent(
336+
session,
337+
'gesture',
338+
['pan', '392', '437', '-170', '0', '400'],
339+
{
340+
kind: 'pan',
341+
from: { x: 392, y: 437 },
342+
to: { x: 222, y: 437 },
343+
durationMs: 400,
344+
pointerCount: 2,
345+
},
346+
{},
347+
2_200,
348+
2_600,
349+
);
335350

336351
assert.deepEqual(session.recording?.gestureEvents, [
337352
{
338353
kind: 'swipe',
339354
tMs: 500,
340-
x: 201,
355+
x: 10,
341356
y: 437,
342-
x2: 241,
343-
y2: 407,
357+
x2: 180,
358+
y2: 437,
344359
referenceWidth: 402,
345360
referenceHeight: 874,
346361
durationMs: 600,
347362
},
363+
{
364+
kind: 'swipe',
365+
tMs: 1_200,
366+
x: 392,
367+
y: 437,
368+
x2: 222,
369+
y2: 437,
370+
referenceWidth: 402,
371+
referenceHeight: 874,
372+
durationMs: 400,
373+
},
348374
]);
349375
});
350376

src/daemon/recording-gesture-events.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ import { readRecordingNumber } from './recording-values.ts';
55
const DEFAULT_GESTURE_TRAVEL_DURATION_MS = 250;
66
const DEFAULT_PINCH_DURATION_MS = 280;
77

8+
type SwipeTravelEventOptions = {
9+
referenceFrame?: ReferenceFrame;
10+
classifyBackSwipe?: boolean;
11+
};
12+
813
export function buildCanonicalGestureEvents(
914
positionals: string[],
1015
result: Record<string, unknown>,
@@ -20,6 +25,9 @@ export function buildCanonicalGestureEvents(
2025
const from = readPoint(result.from);
2126
const to = readPoint(result.to);
2227
if (!from || !to) return [];
28+
const allowBackSwipeClassification =
29+
(result.kind === 'pan' || result.kind === 'fling') &&
30+
readRecordingNumber(result.pointerCount) !== 2;
2331
return [
2432
buildSwipeTravelEvent(
2533
tMs,
@@ -32,7 +40,10 @@ export function buildCanonicalGestureEvents(
3240
result.durationMs,
3341
DEFAULT_GESTURE_TRAVEL_DURATION_MS,
3442
),
35-
referenceFrame,
43+
{
44+
referenceFrame,
45+
classifyBackSwipe: allowBackSwipeClassification,
46+
},
3647
),
3748
];
3849
}
@@ -68,9 +79,10 @@ export function buildSwipeTravelEvent(
6879
x2: number,
6980
y2: number,
7081
durationMs: number,
71-
referenceFrame?: ReferenceFrame,
82+
options: SwipeTravelEventOptions = {},
7283
): RecordingGestureEvent {
73-
const kind = classifySwipeKind(x, y, x2, y2, referenceFrame);
84+
const { referenceFrame, classifyBackSwipe = true } = options;
85+
const kind = classifyBackSwipe ? classifySwipeKind(x, y, x2, y2, referenceFrame) : 'swipe';
7486
if (kind === 'back-swipe') {
7587
return {
7688
kind,

src/daemon/recording-gestures.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,9 @@ function buildSwipeEvents(
311311
return Array.from({ length: count }, (_, index) => {
312312
const { startX, startY, endX, endY } = resolveSwipePathForIndex(index, pattern, x1, y1, x2, y2);
313313
const startTime = tMs + index * (durationMs + pauseMs);
314-
return buildSwipeTravelEvent(startTime, startX, startY, endX, endY, durationMs, referenceFrame);
314+
return buildSwipeTravelEvent(startTime, startX, startY, endX, endY, durationMs, {
315+
referenceFrame,
316+
});
315317
});
316318
}
317319

0 commit comments

Comments
 (0)