fix: prevent resizing elements on the timeline further than the timeline start

This commit is contained in:
Maze Winther
2025-07-26 13:13:27 +02:00
parent f149ab3b6c
commit 14475dc9a6
2 changed files with 9 additions and 5 deletions
@@ -133,8 +133,10 @@ export function useTimelineElementResize({
if (canExtendElementDuration()) { if (canExtendElementDuration()) {
// Text/Image: extend element to the left by moving startTime and increasing duration // Text/Image: extend element to the left by moving startTime and increasing duration
const extensionAmount = Math.abs(calculated); const extensionAmount = Math.abs(calculated);
const newStartTime = element.startTime - extensionAmount; const maxExtension = element.startTime;
const newDuration = element.duration + extensionAmount; const actualExtension = Math.min(extensionAmount, maxExtension);
const newStartTime = element.startTime - actualExtension;
const newDuration = element.duration + actualExtension;
// Keep trimStart at 0 and extend the element // Keep trimStart at 0 and extend the element
updateElementTrim( updateElementTrim(
+5 -3
View File
@@ -754,13 +754,16 @@ export const useTimelineStore = create<TimelineStore>((set, get) => {
pushHistory = true pushHistory = true
) => { ) => {
if (pushHistory) get().pushHistory(); if (pushHistory) get().pushHistory();
const clampedStartTime = Math.max(0, startTime);
updateTracksAndSave( updateTracksAndSave(
get()._tracks.map((track) => get()._tracks.map((track) =>
track.id === trackId track.id === trackId
? { ? {
...track, ...track,
elements: track.elements.map((element) => elements: track.elements.map((element) =>
element.id === elementId ? { ...element, startTime } : element element.id === elementId
? { ...element, startTime: clampedStartTime }
: element
), ),
} }
: track : track
@@ -799,8 +802,7 @@ export const useTimelineStore = create<TimelineStore>((set, get) => {
const updatedElements = currentTrack.elements.map((currentElement) => { const updatedElements = currentTrack.elements.map((currentElement) => {
if (currentElement.id === elementId && currentTrack.id === trackId) { if (currentElement.id === elementId && currentTrack.id === trackId) {
// Update the moved element return { ...currentElement, startTime: Math.max(0, newStartTime) };
return { ...currentElement, startTime: newStartTime };
} }
// Only apply ripple effects if we should process this track // Only apply ripple effects if we should process this track