mirror of
https://github.com/OpenCut-app/OpenCut.git
synced 2026-07-13 21:52:53 +02:00
fix: prevent resizing elements on the timeline further than the timeline start
This commit is contained in:
@@ -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(
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user