Skip to content

YC (S26) | Open Computer History | Continuously record your company computer work, map your workflows, help you find work worth automating, and power your agents' context

fix(timeline): restore pinch-to-zoom, scale scroll speed by zoom level

Louis Beaumont523a629e0d28
diff --git a/apps/screenpipe-app-tauri/components/rewind/timeline.tsx b/apps/screenpipe-app-tauri/components/rewind/timeline.tsx
index 2c800a870..f19eae371 100644
--- a/apps/screenpipe-app-tauri/components/rewind/timeline.tsx
+++ b/apps/screenpipe-app-tauri/components/rewind/timeline.tsx
@@ -91,6 +91,26 @@ export default function Timeline() {
setCurrentIndex(index);
});
+ // Zoom state — owned here so both scroll handler and TimelineSlider share it
+ const [zoomLevel, setZoomLevel] = useState(1);
+ const [targetZoom, setTargetZoom] = useState(1);
+ const MIN_ZOOM = 0.25;
+ const MAX_ZOOM = 4;
+ const isZoomingRef = useRef(false);
+ const zoomTimeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null);
+
+ // Smooth zoom animation
+ useEffect(() => {
+ if (Math.abs(zoomLevel - targetZoom) < 0.01) {
+ if (zoomLevel !== targetZoom) setZoomLevel(targetZoom);
+ return;
+ }
+ const id = requestAnimationFrame(() => {
+ setZoomLevel(prev => prev + (targetZoom - prev) * 0.15);
+ });
+ return () => cancelAnimationFrame(id);
+ }, [zoomLevel, targetZoom]);
+
// Flag to prevent frame-date sync from fighting with intentional navigation
const isNavigatingRef = useRef(false);
@@ -571,6 +591,32 @@ export default function Timeline() {
return;
}
+ // Pinch gesture on trackpad sends ctrlKey=true
+ // Cmd+Scroll on mouse sends metaKey=true — handle as zoom
+ if (e.ctrlKey || e.metaKey) {
+ e.preventDefault();
+ e.stopPropagation();
+
+ // Mark zooming to suppress scroll for a short debounce
+ isZoomingRef.current = true;
+ if (zoomTimeoutRef.current) clearTimeout(zoomTimeoutRef.current);
+ zoomTimeoutRef.current = setTimeout(() => {
+ isZoomingRef.current = false;
+ }, 150);
+
+ const zoomDelta = -e.deltaY * 0.008;
+ setTargetZoom((prev) =>
+ Math.min(MAX_ZOOM, Math.max(MIN_ZOOM, prev * (1 + zoomDelta))),
+ );
+ return;
+ }
+
+ // Don't scroll while a zoom gesture is still settling
+ if (isZoomingRef.current) {
+ e.preventDefault();
+ return;
+ }
+
e.preventDefault();
e.stopPropagation();
@@ -578,15 +624,20 @@ export default function Timeline() {
const scrollIntensity = Math.abs(e.deltaY);
const direction = -Math.sign(e.deltaY);
+ // Scale scroll speed by zoom: zoomed-out → faster, zoomed-in → slower
+ const zoomMultiplier = 1 / zoomLevel;
+
// Change this if you want limit the index change
const limitIndexChange = Infinity;
- // Adjust index change based on scroll intensity
+ // Adjust index change based on scroll intensity and zoom
const indexChange =
direction *
Math.min(
limitIndexChange,
- Math.ceil(Math.pow(scrollIntensity / 50, 1.5)),
+ Math.max(1, Math.ceil(
+ Math.pow(scrollIntensity / 50, 1.5) * zoomMultiplier,
+ )),
);
requestAnimationFrame(() => {
@@ -607,7 +658,7 @@ export default function Timeline() {
16,
{ leading: true, trailing: false },
),
- [frames], // Only depend on frames length changes
+ [frames, zoomLevel], // Re-create when zoom changes
);
useEffect(() => {
@@ -626,6 +677,8 @@ export default function Timeline() {
?.contains(e.target as Node);
if (!isWithinAiPanel && !isWithinAudioPanel && !isWithinTimelineDialog && !isWithinSettingsDialog) {
+ // Always preventDefault — including for pinch (ctrlKey) to block
+ // the browser's native zoom behavior
e.preventDefault();
}
};
@@ -1104,6 +1157,9 @@ export default function Timeline() {
newFramesCount={newFramesCount}
lastFlushTimestamp={lastFlushTimestamp}
isSearchModalOpen={showSearchModal}
+ zoomLevel={zoomLevel}
+ targetZoom={targetZoom}
+ setTargetZoom={setTargetZoom}
/>
) : (
<div className="bg-card/80 backdrop-blur-sm p-4 border-t border-border">
diff --git a/apps/screenpipe-app-tauri/components/rewind/timeline/timeline.tsx b/apps/screenpipe-app-tauri/components/rewind/timeline/timeline.tsx
index d220d8326..164c4d045 100644
--- a/apps/screenpipe-app-tauri/components/rewind/timeline/timeline.tsx
+++ b/apps/screenpipe-app-tauri/components/rewind/timeline/timeline.tsx
@@ -19,6 +19,9 @@ interface TimelineSliderProps {
newFramesCount?: number; // Number of new frames added (for animation)
lastFlushTimestamp?: number; // When frames were last added (to trigger animation)
isSearchModalOpen?: boolean; // When true, disable wheel/focus handling to not interfere with modal
+ zoomLevel: number;
+ targetZoom: number;
+ setTargetZoom: (fn: (prev: number) => number) => void;
}
interface AppGroup {
@@ -126,6 +129,9 @@ export const TimelineSlider = ({
newFramesCount = 0,
lastFlushTimestamp = 0,
isSearchModalOpen = false,
+ zoomLevel,
+ targetZoom,
+ setTargetZoom,
}: TimelineSliderProps) => {
const containerRef = useRef<HTMLDivElement>(null);
const observerTargetRef = useRef<HTMLDivElement>(null);
@@ -148,87 +154,9 @@ export const TimelineSlider = ({
const [activePopoverGroup, setActivePopoverGroup] = useState<number | null>(null);
const [popoverAnchor, setPopoverAnchor] = useState<{ x: number; y: number }>({ x: 0, y: 0 });
- // Zoom state: 1 = normal, >1 = zoomed in, <1 = zoomed out
- // Range: 0.25 (very zoomed out) to 4 (very zoomed in)
- const [zoomLevel, setZoomLevel] = useState(1);
- const [targetZoom, setTargetZoom] = useState(1);
const MIN_ZOOM = 0.25;
const MAX_ZOOM = 4;
- // Smooth zoom animation using requestAnimationFrame
- useEffect(() => {
- if (Math.abs(zoomLevel - targetZoom) < 0.01) {
- if (zoomLevel !== targetZoom) setZoomLevel(targetZoom);
- return;
- }
-
- const animationId = requestAnimationFrame(() => {
- // Ease toward target (lerp with 0.15 factor for smooth animation)
- setZoomLevel(prev => prev + (targetZoom - prev) * 0.15);
- });
-
- return () => cancelAnimationFrame(animationId);
- }, [zoomLevel, targetZoom]);
-
- // Track if we're in a zoom gesture to prevent simultaneous scrolling
- const isZoomingRef = useRef(false);
- const zoomTimeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null);
-
- // Handle pinch-to-zoom (trackpad) and Cmd+Scroll (mouse)
- const handleWheel = useCallback((e: WheelEvent) => {
- // Don't handle wheel events when search modal is open
- if (isSearchModalOpen) return;
-
- // Pinch gesture on trackpad sends ctrlKey=true
- // Cmd+Scroll on mouse sends metaKey=true
- if (e.ctrlKey || e.metaKey) {
- e.preventDefault();
- e.stopPropagation();
-
- // Mark that we're zooming - this prevents scroll from happening
- isZoomingRef.current = true;
- if (zoomTimeoutRef.current) clearTimeout(zoomTimeoutRef.current);
- zoomTimeoutRef.current = setTimeout(() => {
- isZoomingRef.current = false;
- }, 150); // Debounce - wait 150ms after last zoom event
-
- // Calculate zoom delta (negative deltaY = zoom in)
- const zoomDelta = -e.deltaY * 0.008;
-
- setTargetZoom((prev) => {
- const newZoom = Math.min(MAX_ZOOM, Math.max(MIN_ZOOM, prev * (1 + zoomDelta)));
- return newZoom;
- });
- } else if (!isZoomingRef.current) {
- // Only allow scroll when not in a zoom gesture
- // Regular scroll - speed scales inversely with zoom
- // When zoomed out (0.25), scroll moves 4x faster through frames
- // When zoomed in (4), scroll moves 0.25x slower
- const scrollMultiplier = 1 / zoomLevel;
- const framesToSkip = Math.round(e.deltaX * scrollMultiplier * 0.1);
-
- if (framesToSkip !== 0 && onFrameChange) {
- const newIndex = Math.max(0, Math.min(frames.length - 1, currentIndex - framesToSkip));
- if (newIndex !== currentIndex) {
- onFrameChange(newIndex);
- }
- }
- }
- }, [zoomLevel, currentIndex, frames.length, onFrameChange, isSearchModalOpen]);
-
- // Attach wheel event listener for zoom
- useEffect(() => {
- const container = containerRef.current;
- if (!container) return;
-
- // Use passive: false to allow preventDefault for pinch gestures
- container.addEventListener('wheel', handleWheel, { passive: false });
-
- return () => {
- container.removeEventListener('wheel', handleWheel);
- };
- }, [handleWheel]);
-
// Auto-focus container on mount so zoom works immediately
// But skip when search modal is open to not steal focus from modal input
useEffect(() => {