fix: zoom in with playhead on center screen
This commit is contained in:
@@ -3318,6 +3318,8 @@ const App = () => {
|
|||||||
const rulerAnchorRef = useRef(null);
|
const rulerAnchorRef = useRef(null);
|
||||||
const isDraggingRulerRef = useRef(false);
|
const isDraggingRulerRef = useRef(false);
|
||||||
const handlePlayPauseRef = useRef(null);
|
const handlePlayPauseRef = useRef(null);
|
||||||
|
const currentTimeRef = useRef(currentTime);
|
||||||
|
currentTimeRef.current = currentTime;
|
||||||
|
|
||||||
// ── Keyboard Shortcuts ──
|
// ── Keyboard Shortcuts ──
|
||||||
const handleUndoRef = useRef(handleUndo);
|
const handleUndoRef = useRef(handleUndo);
|
||||||
@@ -4881,18 +4883,16 @@ const App = () => {
|
|||||||
const handleWheel = e => {
|
const handleWheel = e => {
|
||||||
if (e.ctrlKey || e.metaKey) {
|
if (e.ctrlKey || e.metaKey) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
const rect = timeline.getBoundingClientRect();
|
|
||||||
const mouseXInViewport = e.clientX - rect.left;
|
|
||||||
const mouseXInCanvas = mouseXInViewport + timeline.scrollLeft;
|
|
||||||
const anchorTime = mouseXInCanvas / zoom;
|
|
||||||
const zoomFactor = e.deltaY > 0 ? 0.9 : 1.1;
|
const zoomFactor = e.deltaY > 0 ? 0.9 : 1.1;
|
||||||
setZoom(prevZoom => {
|
setZoom(prevZoom => {
|
||||||
let newZoom = prevZoom * zoomFactor;
|
let newZoom = prevZoom * zoomFactor;
|
||||||
if (newZoom < minZoom) newZoom = minZoom;
|
if (newZoom < minZoom) newZoom = minZoom;
|
||||||
if (newZoom > 50000) newZoom = 50000;
|
if (newZoom > 50000) newZoom = 50000;
|
||||||
const newMouseXInCanvas = anchorTime * newZoom;
|
|
||||||
requestAnimationFrame(() => {
|
requestAnimationFrame(() => {
|
||||||
timeline.scrollLeft = newMouseXInCanvas - mouseXInViewport;
|
const centerTime = currentTimeRef.current;
|
||||||
|
const newCenterX = centerTime * newZoom;
|
||||||
|
const viewportWidth = timeline.clientWidth;
|
||||||
|
timeline.scrollLeft = newCenterX - viewportWidth / 2;
|
||||||
});
|
});
|
||||||
return newZoom;
|
return newZoom;
|
||||||
});
|
});
|
||||||
@@ -4905,7 +4905,7 @@ const App = () => {
|
|||||||
passive: false
|
passive: false
|
||||||
});
|
});
|
||||||
return () => timeline.removeEventListener('wheel', handleWheel);
|
return () => timeline.removeEventListener('wheel', handleWheel);
|
||||||
}, [zoom, minZoom, maxDuration, activeTab]);
|
}, [minZoom]);
|
||||||
|
|
||||||
// ── Update Playhead ──
|
// ── Update Playhead ──
|
||||||
const startSubTabPlayback = (st, offsetWallTime) => {
|
const startSubTabPlayback = (st, offsetWallTime) => {
|
||||||
|
|||||||
@@ -3318,6 +3318,8 @@ const App = () => {
|
|||||||
const rulerAnchorRef = useRef(null);
|
const rulerAnchorRef = useRef(null);
|
||||||
const isDraggingRulerRef = useRef(false);
|
const isDraggingRulerRef = useRef(false);
|
||||||
const handlePlayPauseRef = useRef(null);
|
const handlePlayPauseRef = useRef(null);
|
||||||
|
const currentTimeRef = useRef(currentTime);
|
||||||
|
currentTimeRef.current = currentTime;
|
||||||
|
|
||||||
// ── Keyboard Shortcuts ──
|
// ── Keyboard Shortcuts ──
|
||||||
const handleUndoRef = useRef(handleUndo);
|
const handleUndoRef = useRef(handleUndo);
|
||||||
@@ -4881,18 +4883,16 @@ const App = () => {
|
|||||||
const handleWheel = e => {
|
const handleWheel = e => {
|
||||||
if (e.ctrlKey || e.metaKey) {
|
if (e.ctrlKey || e.metaKey) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
const rect = timeline.getBoundingClientRect();
|
|
||||||
const mouseXInViewport = e.clientX - rect.left;
|
|
||||||
const mouseXInCanvas = mouseXInViewport + timeline.scrollLeft;
|
|
||||||
const anchorTime = mouseXInCanvas / zoom;
|
|
||||||
const zoomFactor = e.deltaY > 0 ? 0.9 : 1.1;
|
const zoomFactor = e.deltaY > 0 ? 0.9 : 1.1;
|
||||||
setZoom(prevZoom => {
|
setZoom(prevZoom => {
|
||||||
let newZoom = prevZoom * zoomFactor;
|
let newZoom = prevZoom * zoomFactor;
|
||||||
if (newZoom < minZoom) newZoom = minZoom;
|
if (newZoom < minZoom) newZoom = minZoom;
|
||||||
if (newZoom > 50000) newZoom = 50000;
|
if (newZoom > 50000) newZoom = 50000;
|
||||||
const newMouseXInCanvas = anchorTime * newZoom;
|
|
||||||
requestAnimationFrame(() => {
|
requestAnimationFrame(() => {
|
||||||
timeline.scrollLeft = newMouseXInCanvas - mouseXInViewport;
|
const centerTime = currentTimeRef.current;
|
||||||
|
const newCenterX = centerTime * newZoom;
|
||||||
|
const viewportWidth = timeline.clientWidth;
|
||||||
|
timeline.scrollLeft = newCenterX - viewportWidth / 2;
|
||||||
});
|
});
|
||||||
return newZoom;
|
return newZoom;
|
||||||
});
|
});
|
||||||
@@ -4905,7 +4905,7 @@ const App = () => {
|
|||||||
passive: false
|
passive: false
|
||||||
});
|
});
|
||||||
return () => timeline.removeEventListener('wheel', handleWheel);
|
return () => timeline.removeEventListener('wheel', handleWheel);
|
||||||
}, [zoom, minZoom, maxDuration, activeTab]);
|
}, [minZoom]);
|
||||||
|
|
||||||
// ── Update Playhead ──
|
// ── Update Playhead ──
|
||||||
const startSubTabPlayback = (st, offsetWallTime) => {
|
const startSubTabPlayback = (st, offsetWallTime) => {
|
||||||
|
|||||||
Binary file not shown.
Reference in New Issue
Block a user