De-duplicate code

This commit is contained in:
Andrew Kordampalos
2025-06-23 22:32:17 +03:00
parent 2a1ac8fcf7
commit 267a590d04

View File

@ -290,18 +290,20 @@ export function Timeline() {
} }
}; };
// Deselect all clips when clicking empty timeline area and seek to clicked position const handleSeekToPosition = (e: React.MouseEvent) => {
const handleTimelineAreaClick = (e: React.MouseEvent) => {
// Only clear selection if the click target is the timeline background (not a child/clip)
if (e.target === e.currentTarget) {
clearSelectedClips();
// Calculate the clicked time position and seek to it
const rect = e.currentTarget.getBoundingClientRect(); const rect = e.currentTarget.getBoundingClientRect();
const clickX = e.clientX - rect.left; const clickX = e.clientX - rect.left;
const clickedTime = clickX / (50 * zoomLevel); const clickedTime = clickX / (50 * zoomLevel);
const clampedTime = Math.max(0, Math.min(duration, clickedTime)); const clampedTime = Math.max(0, Math.min(duration, clickedTime));
seek(clampedTime); seek(clampedTime);
};
const handleTimelineAreaClick = (e: React.MouseEvent) => {
if (e.target === e.currentTarget) {
clearSelectedClips();
// Calculate the clicked time position and seek to it
handleSeekToPosition(e);
} }
}; };
@ -500,11 +502,7 @@ export function Timeline() {
}} }}
onClick={(e) => { onClick={(e) => {
// Calculate the clicked time position and seek to it // Calculate the clicked time position and seek to it
const rect = e.currentTarget.getBoundingClientRect(); handleSeekToPosition(e);
const clickX = e.clientX - rect.left;
const clickedTime = clickX / (50 * zoomLevel);
const clampedTime = Math.max(0, Math.min(duration, clickedTime));
seek(clampedTime);
}} }}
> >
{/* Time markers */} {/* Time markers */}