summaryrefslogtreecommitdiff
path: root/apps/web/src/hooks
diff options
context:
space:
mode:
authorMaze Winther <mazewinther@gmail.com>2025-08-01 09:51:54 +0200
committerMaze Winther <mazewinther@gmail.com>2025-08-01 09:51:54 +0200
commit09cb8c8d984e3e82f60e28b352508c876423fbdf (patch)
tree089b31e11f711eaa378ff39e1901674d835c1569 /apps/web/src/hooks
parentb00d6d5fb61229fcc035cc9680731f042d03b919 (diff)
downloadopencut-09cb8c8d984e3e82f60e28b352508c876423fbdf.tar.gz
fix: resize not matching with frames
Diffstat (limited to 'apps/web/src/hooks')
-rw-r--r--apps/web/src/hooks/use-timeline-element-resize.ts29
1 files changed, 23 insertions, 6 deletions
diff --git a/apps/web/src/hooks/use-timeline-element-resize.ts b/apps/web/src/hooks/use-timeline-element-resize.ts
index d57533e0..ba13e05a 100644
--- a/apps/web/src/hooks/use-timeline-element-resize.ts
+++ b/apps/web/src/hooks/use-timeline-element-resize.ts
@@ -221,17 +221,34 @@ export function useTimelineElementResize({
}
} else {
// Normal trimming within original duration
- const maxTrimEnd = element.duration - resizing.initialTrimStart - 0.1; // Leave at least 0.1s visible
- const newTrimEnd = snapTimeToFrame(
- Math.max(0, Math.min(maxTrimEnd, calculated)),
- projectFps
+ // Calculate the desired end time based on mouse movement
+ const currentEndTime =
+ element.startTime +
+ element.duration -
+ element.trimStart -
+ element.trimEnd;
+ const desiredEndTime = currentEndTime + deltaTime;
+
+ // Snap the desired end time to frame
+ const snappedEndTime = snapTimeToFrame(desiredEndTime, projectFps);
+
+ // Calculate what trimEnd should be to achieve this snapped end time
+ const newTrimEnd = Math.max(
+ 0,
+ element.duration -
+ element.trimStart -
+ (snappedEndTime - element.startTime)
);
+ // Ensure we don't trim more than available content (leave at least 0.1s visible)
+ const maxTrimEnd = element.duration - element.trimStart - 0.1;
+ const finalTrimEnd = Math.min(maxTrimEnd, newTrimEnd);
+
updateElementTrim(
track.id,
element.id,
- resizing.initialTrimStart,
- newTrimEnd,
+ element.trimStart,
+ finalTrimEnd,
false
);
}