Skip to content

Record your screen, ship a demo. Free and open-source, GPU-accelerated, no watermarks, no subscriptions. Windows, macOS, Linux. Actively maintained.

fix(auto-zoom): drop the pointer's rest on Stop along with the Stop click

EtienneLescot0da75dedc3d6
diff --git a/src/lib/ai-edition/timeline/zoom-suggestions.test.ts b/src/lib/ai-edition/timeline/zoom-suggestions.test.ts
index d8ba654ff..9d23aca68 100644
--- a/src/lib/ai-edition/timeline/zoom-suggestions.test.ts
+++ b/src/lib/ai-edition/timeline/zoom-suggestions.test.ts
@@ -715,5 +715,28 @@ describe("buildAutoZoomSuggestionsForClips", () => {
});
expect(suggestions.map((s) => s.focus)).toEqual([{ cx: 0.3, cy: 0.3 }]);
});
+
+ it("ignores the pointer resting on Stop before that click", () => {
+ // Hover-then-Stop: the pointer sits on the button from 18.8 s, clicks at 19.8 s,
+ // and the telemetry ends at 19.9 s. That still run is a dwell, and it goes with its click.
+ const hover = Array.from({ length: 34 }, (_, i) => ({
+ timeMs: 18800 + i * 33,
+ cx: 0.5,
+ cy: 0.92,
+ }));
+ const suggestions = buildAutoZoomSuggestionsForClips({
+ cursorTelemetry: [
+ click(6000, 0.3, 0.3),
+ ...hover,
+ click(19800, 0.5, 0.92),
+ { timeMs: 19900, cx: 0.5, cy: 0.92 },
+ ],
+ assetId: "a1",
+ clips: [clip("clip_1", "a1", 0, 20, 0), clip("clip_2", "a2", 0, 20, 20)],
+ existingRegions: [],
+ defaultDurationMs: 2000,
+ });
+ expect(suggestions.map((s) => s.focus)).toEqual([{ cx: 0.3, cy: 0.3 }]);
+ });
});
});
diff --git a/src/lib/ai-edition/timeline/zoom-suggestions.ts b/src/lib/ai-edition/timeline/zoom-suggestions.ts
index 312308337..97e3a2ba8 100644
--- a/src/lib/ai-edition/timeline/zoom-suggestions.ts
+++ b/src/lib/ai-edition/timeline/zoom-suggestions.ts
@@ -232,10 +232,20 @@ export function buildAutoZoomSuggestions(options: {
}
const ignoreClicksFromMs = options.ignoreClicksFromMs ?? Infinity;
- const dwellCandidates = detectZoomDwellCandidates(normalizedSamples);
- const clickCandidates = detectZoomClickCandidates(normalizedSamples).filter(
+ const allClicks = detectZoomClickCandidates(normalizedSamples);
+ const clickCandidates = allClicks.filter(
(candidate) => candidate.centerTimeMs < ignoreClicksFromMs,
);
+ const ignoredClicks = allClicks.filter(
+ (candidate) => candidate.centerTimeMs >= ignoreClicksFromMs,
+ );
+ // The pointer usually rests on Stop before the click: that dwell goes with the click.
+ const dwellCandidates = detectZoomDwellCandidates(normalizedSamples).filter(
+ (dwell) =>
+ !ignoredClicks.some(
+ (click) => Math.abs(click.centerTimeMs - dwell.centerTimeMs) <= dwell.strength / 2,
+ ),
+ );
if (dwellCandidates.length === 0 && clickCandidates.length === 0) {
return [];
}