From 503e73861768aa220ffed32d5c723c5bdecbafed Mon Sep 17 00:00:00 2001 From: GeorgeCaoJ Date: Tue, 24 Jun 2025 14:25:29 +0800 Subject: [PATCH] feat: add context menu in tracks and zooming in timeline --- apps/web/src/components/editor/timeline.tsx | 52 ++++++++++++++++----- 1 file changed, 41 insertions(+), 11 deletions(-) diff --git a/apps/web/src/components/editor/timeline.tsx b/apps/web/src/components/editor/timeline.tsx index ce81f9e..6c4063f 100644 --- a/apps/web/src/components/editor/timeline.tsx +++ b/apps/web/src/components/editor/timeline.tsx @@ -49,6 +49,7 @@ export function Timeline() { const [zoomLevel, setZoomLevel] = useState(1); const dragCounterRef = useRef(0); const timelineRef = useRef(null); + const [isInTimeline, setIsInTimeline] = useState(false); // Unified context menu state const [contextMenu, setContextMenu] = useState<{ @@ -477,10 +478,29 @@ export function Timeline() { toast.success("Deleted selected clip(s)"); }; + + // Prevent explorer zooming in/out when in timeline + useEffect(() => { + const preventZoom = (e: WheelEvent) => { + if (isInTimeline && (e.ctrlKey || e.metaKey)) { + e.preventDefault(); + } + }; + + document.addEventListener('wheel', preventZoom, { passive: false }); + + return () => { + document.removeEventListener('wheel', preventZoom); + }; + }, [isInTimeline]); + return (
setIsInTimeline(true)} + onMouseLeave={() => setIsInTimeline(false)} + onWheel={handleWheel} > {/* Show overlay when dragging media over the timeline */} {isDragOver && ( @@ -758,25 +778,35 @@ export function Timeline() {
{ + e.preventDefault(); + setContextMenu({ + type: 'track', + trackId: track.id, + x: e.clientX, + y: e.clientY, + }); + }} > -
+
- + {track.name} - {track.muted && ( - - Muted - - )}
+ {track.muted && ( + + Muted + + )}
))}