Skip to content

🎥 Make videos programmatically with React

fix(studio): make rolling edits and trim targets consistent

JonnyBurgerdb4b39581589
diff --git a/packages/studio/src/components/Timeline/TimelineSequence.tsx b/packages/studio/src/components/Timeline/TimelineSequence.tsx
index 64e9f936b6..4f6cc02533 100644
--- a/packages/studio/src/components/Timeline/TimelineSequence.tsx
+++ b/packages/studio/src/components/Timeline/TimelineSequence.tsx
@@ -76,6 +76,7 @@ import {
} from './get-timeline-scene-clip-path';
import {getTimelineSequenceVisibleLayout} from './get-timeline-sequence-visible-layout';
import {getTimelineTransitionNeighbors} from './get-timeline-transition-neighbors';
+import {getTimelineTrimHandleLayout} from './get-timeline-trim-handle-layout';
import {getTimelineVolume} from './get-timeline-volume';
import {getCurrentFrame} from './imperative-state';
import {LoopedTimelineIndicator} from './LoopedTimelineIndicators';
@@ -142,7 +143,6 @@ import {
const NEGATIVE_START_BORDER_WIDTH = 1;
const EDGE_DRAG_HIGHLIGHT_WIDTH = 12;
-const MIN_SECONDARY_LEFT_EDGE_ACTION_WIDTH = 32;
const transitionVerticalInset = Math.round(TIMELINE_PACKED_TRACK_HEIGHT * 0.2);
const transitionHeight =
TIMELINE_PACKED_TRACK_HEIGHT - transitionVerticalInset * 2;
@@ -1050,9 +1050,7 @@ const TimelineSequenceBar: React.FC<{
) : null}
</div>
)}
- {isTransition ? null : (
- <div style={{pointerEvents: 'auto'}}>{edgeDragHandles}</div>
- )}
+ {isTransition ? null : edgeDragHandles}
</div>
);
};
@@ -1382,17 +1380,6 @@ const useTimelineSequenceState = (props: TimelineSequenceProps) => {
isStudioInteractivityEnabled() &&
propStatusesForOverride?.trimBefore?.status === 'static',
);
- const previousCascadingSequenceNodePath = previousCascadingOverrideId
- ? overrideIdToNodePathMappingsRef.current[previousCascadingOverrideId]
- : null;
- const previousCascadingSequenceCanResize = Boolean(
- isStudioInteractivityEnabled() &&
- previousCascadingSequenceNodePath &&
- Internals.getPropStatusesCtx(
- propStatuses,
- previousCascadingSequenceNodePath,
- )?.durationInFrames?.status === 'static',
- );
const {previewServerState} = useContext(StudioServerConnectionCtx);
const showPremountingSetting = getStudioShowPremounting();
const premountSelected = useIsPremountingSelected(
@@ -1821,56 +1808,42 @@ const useTimelineSequenceState = (props: TimelineSequenceProps) => {
isTimelineSequenceLeftEdgeDraggable(s) &&
nodePath !== null &&
validatedLocation !== null &&
- (isTransitionSeriesSequence(s)
+ (isTransitionSeriesSequence(s) ||
+ (isCascadingSequence(s) && !isFirstCascadingSequence)
? durationCanUpdate && trimBeforeCanUpdate
: isFirstCascadingSequence
? trimBeforeCanUpdate
- : previousCascadingSequenceId !== null
- ? previousCascadingSequenceCanResize
- : fromCanUpdate && durationCanUpdate && trimBeforeCanUpdate);
- const previousTouchingNodePath = previousTouchingOverrideId
- ? overrideIdToNodePathMappingsRef.current[previousTouchingOverrideId]
- : null;
- const transitionRollingEnabled =
- (s.timelineTrack?.role === 'transition' || isTransitionSeriesSequence(s)) &&
- previewInteractive &&
- [transitionNeighbors?.previous, transitionNeighbors?.next].every(
- (sequence) => {
- const path = sequence?.controls?.overrideId
- ? overrideIdToNodePathMappingsRef.current[
- sequence.controls.overrideId
- ]
- : null;
- return (
- sequence &&
- path &&
- isTimelineSequenceDurationDraggable(sequence) &&
- sequence.frozenFrame === null &&
- Internals.getPropStatusesCtx(propStatuses, path)?.durationInFrames
- ?.status === 'static' &&
- (sequence !== transitionNeighbors?.next ||
- Internals.getPropStatusesCtx(propStatuses, path)?.trimBefore
- ?.status === 'static')
- );
- },
- );
- const rollingEnabled =
- transitionRollingEnabled ||
- Boolean(
- showLeftEdgeDragHandle &&
- !s.loopDisplay &&
- previousTouchingSequence &&
- !previousTouchingSequence.loopDisplay &&
- previousTouchingNodePath &&
- isTimelineSequenceDurationDraggable(previousTouchingSequence) &&
- previousTouchingSequence.frozenFrame === null &&
- s.frozenFrame === null &&
- (!('frozenMediaFrame' in previousTouchingSequence) ||
- previousTouchingSequence.frozenMediaFrame === null) &&
- (!('frozenMediaFrame' in s) || s.frozenMediaFrame === null) &&
- Internals.getPropStatusesCtx(propStatuses, previousTouchingNodePath)
- ?.durationInFrames?.status === 'static',
- );
+ : fromCanUpdate && durationCanUpdate && trimBeforeCanUpdate);
+ const canRoll = (previous: TSequence | null, next: TSequence | null) => {
+ if (!previewInteractive || !previous || !next) return false;
+ return [previous, next].every((sequence) => {
+ const path = sequence.controls?.overrideId
+ ? overrideIdToNodePathMappingsRef.current[sequence.controls.overrideId]
+ : null;
+ const statuses = path
+ ? Internals.getPropStatusesCtx(propStatuses, path)
+ : null;
+ return Boolean(
+ path &&
+ !sequence.loopDisplay &&
+ isTimelineSequenceDurationDraggable(sequence) &&
+ sequence.frozenFrame === null &&
+ (!('frozenMediaFrame' in sequence) ||
+ sequence.frozenMediaFrame === null) &&
+ statuses?.durationInFrames?.status === 'static' &&
+ (sequence !== next ||
+ (statuses.trimBefore?.status === 'static' &&
+ (isCascadingSequence(sequence) ||
+ statuses.from?.status === 'static'))),
+ );
+ });
+ };
+
+ const rollingEnabled = canRoll(
+ transitionNeighbors?.previous ?? previousTouchingSequence,
+ transitionNeighbors?.next ?? s,
+ );
+ const nextRollingEnabled = canRoll(s, nextTouchingSequence);
const hasCaptionsSchema = Object.values(s.controls?.schema ?? {}).some(
(field) => field.type === 'remotion-captions',
);
@@ -1890,8 +1863,7 @@ const useTimelineSequenceState = (props: TimelineSequenceProps) => {
endEdgeDrag,
clearEdgeHighlight,
rollingEnabled,
- previousTouchingSequence,
- nextTouchingSequence,
+ nextRollingEnabled,
extendVideoLastFrame,
mediaStartFrame,
mediaLoopStartFrame,
@@ -1901,7 +1873,6 @@ const useTimelineSequenceState = (props: TimelineSequenceProps) => {
validatedLocation,
nodePath,
fromCanUpdate,
- durationCanUpdate,
trimBeforeCanUpdate,
showPremounting,
previewConnected,
@@ -1974,8 +1945,7 @@ const TimelineSequenceLayoutInner: React.FC<{
endEdgeDrag,
clearEdgeHighlight,
rollingEnabled,
- previousTouchingSequence,
- nextTouchingSequence,
+ nextRollingEnabled,
extendVideoLastFrame,
mediaStartFrame,
mediaLoopStartFrame,
@@ -1985,7 +1955,6 @@ const TimelineSequenceLayoutInner: React.FC<{
validatedLocation,
nodePath,
fromCanUpdate,
- durationCanUpdate,
trimBeforeCanUpdate,
showPremounting,
previewConnected,
@@ -2138,15 +2107,6 @@ const TimelineSequenceLayoutInner: React.FC<{
? Math.round(outgoingTransitionStart * frameIncrement) -
visibleLayout.marginLeft
: null;
- const incomingTransitionEnd = isTransitionSeriesSequence(s)
- ? (sceneRange?.transitionInEnd ?? null)
- : null;
- const transitionEndOffset =
- incomingTransitionEnd !== null && visibleLayout?.media
- ? Math.round(incomingTransitionEnd * frameIncrement) -
- visibleLayout.marginLeft -
- visibleLayout.media.left
- : null;
const rightTrimHandleVisible =
transitionStartOffset !== null
? transitionStartOffset >= 0 &&
@@ -2387,25 +2347,56 @@ const TimelineSequenceLayoutInner: React.FC<{
const canShowSecondaryLeftEdgeAction =
!isTransitionSeriesSequence(s) &&
- (isMedia || (isCascadingSequence(s) && !isFirstCascadingSequence)) &&
+ isMedia &&
isTimelineSequenceLeftEdgeDraggable(s) &&
nodePath !== null &&
validatedLocation !== null &&
- trimBeforeCanUpdate &&
- (isMedia || durationCanUpdate) &&
- (transitionEndOffset === null || transitionEndOffset >= 0) &&
- (visibleLayout?.media?.width ?? 0) - (transitionEndOffset ?? 0) >=
- MIN_SECONDARY_LEFT_EDGE_ACTION_WIDTH;
+ trimBeforeCanUpdate;
const secondaryLeftEdgeAction = canShowSecondaryLeftEdgeAction
- ? isMedia
- ? 'source-only'
- : 'self-trim'
+ ? 'source-only'
: null;
if ((maxMediaDuration === null && !s.loopDisplay) || visibleLayout === null) {
return trimOutline;
}
+ const showLeftActions = Boolean(
+ (showLeftEdgeDragHandle ||
+ secondaryLeftEdgeAction ||
+ (s.timelineTrack?.role === 'transition' && rollingEnabled)) &&
+ (s.timelineTrack?.role === 'transition' ||
+ visibleLayout.media?.offset === 0) &&
+ (negativeStartWidth === 0 || activeTrimEdge === 'left') &&
+ nodePathInfo &&
+ validatedLocation,
+ );
+ const leftTrimEnabled =
+ s.timelineTrack?.role !== 'transition' &&
+ showLeftEdgeDragHandle &&
+ visibleLayout.media?.offset === 0;
+ const showRightActions = Boolean(
+ s.timelineTrack?.role !== 'transition' &&
+ showRightEdgeDragHandle &&
+ rightTrimHandleVisible &&
+ nodePathInfo &&
+ validatedLocation,
+ );
+ const leftEdgeOffset =
+ s.timelineTrack?.role === 'transition'
+ ? 0
+ : (visibleLayout.media?.left ?? 0);
+ const rightEdgeOffset = transitionStartOffset ?? visibleLayout.width;
+ const trimHandleLayout = getTimelineTrimHandleLayout({
+ leftEdge: leftEdgeOffset,
+ rightEdge: rightEdgeOffset,
+ rolling: showLeftActions && rollingEnabled,
+ leftTrim: showLeftActions && leftTrimEnabled,
+ secondary: showLeftActions && secondaryLeftEdgeAction !== null,
+ rightTrim: showRightActions,
+ nextRolling: nextRollingEnabled,
+ activeEdge: isEdgeDragging ? activeEdgeHighlight : null,
+ });
+
const mediaDisplayOffsetInFrames = visibleLayout.media
? visibleLayout.media.offset / frameIncrement
: 0;
@@ -2469,98 +2460,61 @@ const TimelineSequenceLayoutInner: React.FC<{
onPointerEnter={onPointerEnter}
onClick={onSequenceClick}
edgeDragHandles={
- <>
- {(showLeftEdgeDragHandle ||
- secondaryLeftEdgeAction ||
- (s.timelineTrack?.role === 'transition' && rollingEnabled)) &&
- (s.timelineTrack?.role === 'transition' ||
- visibleLayout.media?.offset === 0 ||
- (secondaryLeftEdgeAction !== null &&
- transitionEndOffset !== null)) &&
- // Keep the captured handle mounted when a trim crosses frame zero.
- (negativeStartWidth === 0 || activeTrimEdge === 'left') &&
- nodePathInfo &&
- validatedLocation ? (
- <div
- style={
+ <div
+ style={{
+ position: 'absolute',
+ inset: 0,
+ pointerEvents: 'none',
+ zIndex: 2,
+ }}
+ >
+ {showLeftActions && nodePathInfo ? (
+ <TimelineSequenceLeftEdgeDragHandle
+ cursor={`${timelineTrimEdgeCursor}, ew-resize`}
+ trimBeforeCursor={`${timelineLeftEdgeCursor}, e-resize`}
+ sourceOnlyCursor={`${timelineSourceOnlyCursor}, ew-resize`}
+ edgeEnabled={leftTrimEnabled}
+ handleLayout={trimHandleLayout}
+ edgeOffset={leftEdgeOffset}
+ edgeMode={
+ isTransitionSeriesSequence(s)
+ ? 'head-trim'
+ : isFirstCascadingSequence
+ ? 'source-only'
+ : 'self-trim'
+ }
+ rollingEnabled={rollingEnabled}
+ fillTarget={s.timelineTrack?.role === 'transition'}
+ isTransitionSeries={
+ isTransitionSeriesSequence(s) ||
s.timelineTrack?.role === 'transition'
- ? {position: 'absolute', inset: 0, pointerEvents: 'none'}
- : {
- position: 'absolute',
- left: visibleLayout.media?.left ?? 0,
- width: visibleLayout.media?.width ?? 0,
- top: 0,
- bottom: 0,
- pointerEvents: 'none',
- }
}
- >
- <TimelineSequenceLeftEdgeDragHandle
- cursor={
- s.timelineTrack?.role === 'transition'
- ? 'default'
- : `${timelineTrimEdgeCursor}, ew-resize`
- }
- trimBeforeCursor={`${timelineLeftEdgeCursor}, e-resize`}
- sourceOnlyCursor={`${timelineSourceOnlyCursor}, ew-resize`}
- edgeEnabled={
- s.timelineTrack?.role !== 'transition' &&
- showLeftEdgeDragHandle &&
- visibleLayout.media?.offset === 0
- }
- edgeMode={
- isTransitionSeriesSequence(s)
- ? 'head-trim'
- : isFirstCascadingSequence
- ? 'source-only'
- : isCascadingSequence(s)
- ? 'ripple'
- : 'self-trim'
- }
- rollingEnabled={rollingEnabled}
- fillTarget={s.timelineTrack?.role === 'transition'}
- isTransitionSeries={
- isTransitionSeriesSequence(s) ||
- s.timelineTrack?.role === 'transition'
- }
- rollingOutset={Math.min(
- 2,
- ((previousTouchingSequence?.duration ?? 0) /
- keyframePlaybackRate) *
- frameIncrement *
- 0.125,
- )}
- touchingPrevious={previousTouchingSequence !== null}
- onHoverEnd={clearEdgeHighlight}
- secondaryAction={secondaryLeftEdgeAction}
- transitionEndOffset={transitionEndOffset}
- nodePathInfo={nodePathInfo}
- windowWidth={windowWidth}
- timelineDurationInFrames={video.durationInFrames ?? 1}
- initialEdgeFrame={
- s.from +
- (s.timelineTrack?.role === 'transition' ? s.duration / 2 : 0)
- }
- fps={video.fps}
- onDragStart={startLeftEdgeDrag}
- onDragEnd={endEdgeDrag}
- onLimitChange={onTrimLimitChange}
- onSelect={onSelect}
- selected={selected}
- />
- </div>
+ onHoverEnd={clearEdgeHighlight}
+ secondaryAction={secondaryLeftEdgeAction}
+ nodePathInfo={nodePathInfo}
+ windowWidth={windowWidth}
+ timelineDurationInFrames={video.durationInFrames ?? 1}
+ initialEdgeFrame={
+ s.from +
+ (s.timelineTrack?.role === 'transition' ? s.duration / 2 : 0)
+ }
+ fps={video.fps}
+ onDragStart={startLeftEdgeDrag}
+ onDragEnd={endEdgeDrag}
+ onLimitChange={onTrimLimitChange}
+ onSelect={onSelect}
+ selected={selected}
+ />
) : null}
- {s.timelineTrack?.role !== 'transition' &&
- showRightEdgeDragHandle &&
- rightTrimHandleVisible &&
- nodePathInfo &&
- validatedLocation ? (
+ {showRightActions &&
+ trimHandleLayout.rightTrim !== null &&
+ nodePathInfo ? (
<TimelineSequenceRightEdgeDragHandle
isTransitionSeries={isTransitionSeriesSequence(s)}
- transitionStartOffset={transitionStartOffset}
- touchingNext={nextTouchingSequence !== null}
+ handleLeft={trimHandleLayout.rightTrim!}
+ edgeOffset={rightEdgeOffset}
onHoverEnd={clearEdgeHighlight}
- cursor={`${isCascadingSequence(s) && !isTransitionSeriesSequence(s) ? timelineTrimEdgeCursor : timelineRightEdgeCursor}, ew-resize`}
+ cursor={`${timelineRightEdgeCursor}, ew-resize`}
nodePathInfo={nodePathInfo}
mediaDurationDragLimits={mediaDurationDragLimits}
windowWidth={windowWidth}
@@ -2585,7 +2539,7 @@ const TimelineSequenceLayoutInner: React.FC<{
selected={selected}
/>
) : null}
- </>
+ </div>
}
>
{s.type === 'audio' && visibleLayout.media ? (
diff --git a/packages/studio/src/components/Timeline/TimelineSequenceRightEdgeDragHandle.tsx b/packages/studio/src/components/Timeline/TimelineSequenceRightEdgeDragHandle.tsx
index 6e44b9cd1b..de71ba46a8 100644
--- a/packages/studio/src/components/Timeline/TimelineSequenceRightEdgeDragHandle.tsx
+++ b/packages/studio/src/components/Timeline/TimelineSequenceRightEdgeDragHandle.tsx
@@ -56,6 +56,10 @@ import {
getTimelineSequenceTimingLimits,
} from './get-timeline-sequence-timing-limits';
import {getTimelineTransitionNeighbors} from './get-timeline-transition-neighbors';
+import {
+ TIMELINE_TRIM_HANDLE_WIDTH,
+ type getTimelineTrimHandleLayout,
+} from './get-timeline-trim-handle-layout';
import {
saveSequenceProps,
type SaveSequencePropChange,
@@ -81,13 +85,6 @@ import {
const {getParentSequencePlaybackRate, sortItemsByCommitOrder} = CanvasInternals;
-const HANDLE_INSET = 6;
-const HANDLE_OUTSET = 8;
-const LEFT_EDGE_HANDLE_INSET = 4;
-const LEFT_EDGE_HANDLE_OUTSET = 4;
-const TRANSITION_CLIP_EDGE_WIDTH = 'min(10px, 25%)';
-const TRANSITION_RIGHT_HANDLE_INSET =
- HANDLE_INSET + HANDLE_OUTSET + LEFT_EDGE_HANDLE_OUTSET + 1;
const timelineSequenceEdgeDragThresholdPx = 4;
export const timelineSequenceFromDragSnapThresholdPx = 10;
@@ -218,8 +215,7 @@ const baseStyle: React.CSSProperties = {
position: 'absolute',
top: 0,
bottom: 0,
- // Keep the middle half of narrow layers available for moving.
- width: `calc(${HANDLE_OUTSET}px + min(${HANDLE_INSET}px, 25%))`,
+ width: TIMELINE_TRIM_HANDLE_WIDTH,
zIndex: 1,
touchAction: 'none',
};
@@ -264,7 +260,7 @@ export type TimelineSequenceLeftEdgeDragTarget = {
readonly positionField: 'from' | null;
// Series trims resize the previous clip; positioned Track clips roll both edges.
readonly ripplePrevious: TimelineSequenceDurationDragTarget | null;
- // A transition roll preserves the incoming source out by moving its source in.
+ // A cascading roll preserves the incoming source out by moving its source in.
readonly rollingDuration: TimelineSequenceDurationDragTarget | null;
readonly timingLimits: ReturnType<
typeof getTimelineSequenceTimingLimits
@@ -1470,12 +1466,39 @@ export const getTimelineSequenceRollingEditTargets = ({
if (
rightTrack &&
(rightTrack.sequence.timelineTrack?.role === 'transition' ||
- isTransitionSeriesSequence(rightTrack.sequence))
+ isCascadingSequence(rightTrack.sequence))
) {
- const neighbors = getTimelineTransitionNeighbors({
+ let neighbors = getTimelineTransitionNeighbors({
sequenceId: rightTrack.sequence.id,
sequences,
});
+ if (isSeriesSequence(rightTrack.sequence)) {
+ // Timeline tracks use composition time; registrations use their parent clock.
+ const originalSequence = sequences.find(
+ (sequence) => sequence.id === rightTrack.sequence.id,
+ )!;
+ const siblings = sortItemsByCommitOrder(
+ sequences.filter(
+ (sequence) =>
+ sequence.parent === originalSequence.parent &&
+ isSeriesSequence(sequence),
+ ),
+ (sequence) => sequence.timelineOrder,
+ );
+ const preceding =
+ siblings[
+ siblings.findIndex(
+ (sequence) => sequence.id === rightTrack.sequence.id,
+ ) - 1
+ ];
+ neighbors =
+ preceding &&
+ Math.abs(preceding.from + preceding.duration - originalSequence.from) <
+ 0.000001
+ ? {previous: preceding, next: originalSequence}
+ : null;
+ }
+
const previous = neighbors
? tracks.find((track) => track.sequence.id === neighbors.previous.id)
: null;
@@ -1489,8 +1512,8 @@ export const getTimelineSequenceRollingEditTargets = ({
propStatuses,
nodePath: next.nodePathInfo.sequenceSubscriptionKey,
}) ||
- !isTransitionSeriesSequence(previous.sequence) ||
- !isTransitionSeriesSequence(next.sequence)
+ !isCascadingSequence(previous.sequence) ||
+ !isCascadingSequence(next.sequence)
) {
return null;
}
@@ -1933,13 +1956,12 @@ const TimelineSequenceLeftEdgeDragHandleInner: React.FC<{
readonly edgeEnabled: boolean;
readonly edgeMode: TimelineSequenceLeftEdgeDragMode;
readonly rollingEnabled: boolean;
- readonly rollingOutset: number;
+ readonly handleLayout: ReturnType<typeof getTimelineTrimHandleLayout>;
+ readonly edgeOffset: number;
readonly fillTarget: boolean;
readonly isTransitionSeries: boolean;
- readonly touchingPrevious: boolean;
readonly onHoverEnd: () => void;
readonly secondaryAction: 'source-only' | 'self-trim' | null;
- readonly transitionEndOffset: number | null;
readonly nodePathInfo: SequenceNodePathInfo;
readonly windowWidth: number;
readonly timelineDurationInFrames: number;
@@ -1961,13 +1983,12 @@ const TimelineSequenceLeftEdgeDragHandleInner: React.FC<{
edgeEnabled,
edgeMode,
rollingEnabled,
- rollingOutset,
+ handleLayout,
+ edgeOffset,
fillTarget,
isTransitionSeries,
- touchingPrevious,
onHoverEnd,
secondaryAction,
- transitionEndOffset,
nodePathInfo,
windowWidth,
timelineDurationInFrames,
@@ -1997,21 +2018,6 @@ const TimelineSequenceLeftEdgeDragHandleInner: React.FC<{
const currentSelection = useCurrentTimelineSelectionStateAsRef();
const [trimTooltip, setTrimTooltip] =
useState<TimelineTrimTooltipState | null>(null);
- const [altKey, setAltKey] = useState(false);
- const [hovered, setHovered] = useState(false);
- useEffect(() => {
- if (edgeMode !== 'head-trim' || !rollingEnabled || !hovered) return;
- const onKey = (event: KeyboardEvent) => setAltKey(event.altKey);
- const onBlur = () => setAltKey(false);
- window.addEventListener('keydown', onKey);
- window.addEventListener('keyup', onKey);
- window.addEventListener('blur', onBlur);
- return () => {
- window.removeEventListener('keydown', onKey);
- window.removeEventListener('keyup', onKey);
- window.removeEventListener('blur', onBlur);
- };
- }, [edgeMode, hovered, rollingEnabled]);
const stopPointerSessionRef = useRef<(() => void) | null>(null);
const dragStateRef = useRef<{
@@ -2149,18 +2155,8 @@ const TimelineSequenceLeftEdgeDragHandleInner: React.FC<{
return;
}
- const mode =
- e.currentTarget.dataset.trimMode === 'head-trim'
- ? e.altKey && rollingEnabled
- ? 'rolling'
- : 'head-trim'
- : e.currentTarget.dataset.trimMode === 'rolling'
- ? 'rolling'
- : e.currentTarget.dataset.trimMode === 'source-only'
- ? 'source-only'
- : e.currentTarget.dataset.trimMode === 'self-trim'
- ? 'self-trim'
- : 'ripple';
+ const mode = e.currentTarget.dataset
+ .trimMode as TimelineSequenceLeftEdgeDragMode;
const trimBeforeOnly = mode === 'source-only';
const activeCursor =
mode === 'ripple' || mode === 'rolling'
@@ -2197,12 +2193,11 @@ const TimelineSequenceLeftEdgeDragHandleInner: React.FC<{
const overrideIdsToNodePaths = overrideIdToNodePathMappingsRef.current;
const propStatuses = propStatusesRef.current;
const handleRect = captureTarget.getBoundingClientRect();
- const initialEdgeClientX = fillTarget
- ? handleRect.left + handleRect.width / 2
- : captureTarget.parentElement!.getBoundingClientRect().left +
- (mode === 'source-only' || mode === 'self-trim'
- ? (transitionEndOffset ?? 0)
- : 0);
+ const initialEdgeClientX =
+ captureTarget.parentElement!.getBoundingClientRect().left +
+ (fillTarget
+ ? captureTarget.parentElement!.getBoundingClientRect().width / 2
+ : edgeOffset);
const initialEdgeClientY = handleRect.top;
const initialTimelineEdge = latestRef.current.initialEdgeFrame;
@@ -2615,9 +2610,8 @@ const TimelineSequenceLeftEdgeDragHandleInner: React.FC<{
sourceOnlyCursor,
windowWidth,
fillTarget,
+ edgeOffset,
isTransitionSeries,
- transitionEndOffset,
- rollingEnabled,
],
);
@@ -2628,71 +2622,16 @@ const TimelineSequenceLeftEdgeDragHandleInner: React.FC<{
};
}, []);
- const equalMediaTrimHandles =
- edgeEnabled &&
- edgeMode === 'self-trim' &&
- secondaryAction === 'source-only' &&
- !isTransitionSeries &&
- !rollingEnabled &&
- !touchingPrevious &&
- transitionEndOffset === null;
- const leftEdgeHandleInset = equalMediaTrimHandles
- ? 8
- : LEFT_EDGE_HANDLE_INSET;
const edgeStyle: React.CSSProperties = {
...baseStyle,
- zIndex: isTransitionSeries ? 2 : baseStyle.zIndex,
- left: isTransitionSeries
- ? 0
- : rollingEnabled && edgeMode !== 'rolling' && edgeMode !== 'head-trim'
- ? 'min(2px, 12.5%)'
- : touchingPrevious
- ? 0
- : -LEFT_EDGE_HANDLE_OUTSET,
- width: isTransitionSeries
- ? TRANSITION_CLIP_EDGE_WIDTH
- : rollingEnabled || touchingPrevious
- ? 'min(10px, 12.5%)'
- : edgeMode === 'source-only'
- ? `calc(${LEFT_EDGE_HANDLE_OUTSET}px + min(14px, 25%))`
- : `calc(${LEFT_EDGE_HANDLE_OUTSET}px + min(${leftEdgeHandleInset}px, 12.5%))`,
- cursor:
- edgeMode === 'head-trim'
- ? altKey && rollingEnabled
- ? cursor
- : trimBeforeCursor
- : edgeMode === 'rolling'
- ? cursor
- : edgeMode === 'ripple'
- ? cursor
- : edgeMode === 'source-only'
- ? sourceOnlyCursor
- : trimBeforeCursor,
+ left: handleLayout.leftTrim ?? 0,
+ cursor: edgeMode === 'source-only' ? sourceOnlyCursor : trimBeforeCursor,
background: TRANSPARENT,
pointerEvents: 'auto',
};
const trimBeforeStyle: React.CSSProperties = {
...baseStyle,
- zIndex: isTransitionSeries ? 2 : baseStyle.zIndex,
- // Keep the incoming head trim inside the solid clip, beyond the overlap.
- left:
- transitionEndOffset !== null
- ? transitionEndOffset + HANDLE_INSET
- : edgeEnabled
- ? rollingEnabled
- ? edgeMode === 'rolling'
- ? 'min(6px, 12.5%)'
- : 'calc(min(2px, 12.5%) + min(10px, 12.5%))'
- : touchingPrevious
- ? 'min(10px, 12.5%)'
- : `min(${leftEdgeHandleInset}px, 12.5%)`
- : 0,
- width:
- transitionEndOffset !== null
- ? 10
- : edgeEnabled
- ? `min(${equalMediaTrimHandles ? 8 : 10}px, 12.5%)`
- : 'min(14px, 25%)',
+ left: handleLayout.secondary ?? 0,
cursor:
secondaryAction === 'source-only' ? sourceOnlyCursor : trimBeforeCursor,
background: TRANSPARENT,
@@ -2705,8 +2644,6 @@ const TimelineSequenceLeftEdgeDragHandleInner: React.FC<{
};
const onLeave = () => {
- setHovered(false);
- setAltKey(false);
if (dragStateRef.current === null) {
onHoverEnd();
}
@@ -2714,7 +2651,7 @@ const TimelineSequenceLeftEdgeDragHandleInner: React.FC<{
return (
<>
- {rollingEnabled && edgeMode !== 'rolling' && edgeMode !== 'head-trim' ? (
+ {rollingEnabled && (fillTarget || handleLayout.rolling !== null) ? (
<div
role="separator"
aria-orientation="vertical"
@@ -2722,10 +2659,9 @@ const TimelineSequenceLeftEdgeDragHandleInner: React.FC<{
data-trim-mode="rolling"
style={{
...baseStyle,
- left: fillTarget ? 0 : -rollingOutset,
- width: fillTarget
- ? '100%'
- : `calc(${rollingOutset}px + min(2px, 12.5%))`,
+ left: fillTarget ? 0 : (handleLayout.rolling ?? 0),
+ width: fillTarget ? '100%' : TIMELINE_TRIM_HANDLE_WIDTH,
+ minWidth: TIMELINE_TRIM_HANDLE_WIDTH,
cursor,
background: TRANSPARENT,
pointerEvents: 'auto',
@@ -2736,43 +2672,24 @@ const TimelineSequenceLeftEdgeDragHandleInner: React.FC<{
onClick={fillTarget ? undefined : (e) => e.stopPropagation()}
/>
) : null}
- {edgeEnabled ? (
+ {edgeEnabled && handleLayout.leftTrim !== null ? (
<div
role="separator"
aria-orientation="vertical"
aria-label={
- edgeMode === 'rolling' ||
- (edgeMode === 'head-trim' && altKey && rollingEnabled)
- ? 'Drag to roll edit'
- : edgeMode === 'source-only'
- ? 'Drag to adjust source start'
- : 'Drag to trim start'
+ edgeMode === 'source-only'
+ ? 'Drag to adjust source start'
+ : 'Drag to trim start'
}
data-trim-mode={edgeMode}
- title={
- edgeMode === 'head-trim' && rollingEnabled
- ? 'Drag to trim start. Option/Alt-drag to roll edit.'
- : undefined
- }
style={edgeStyle}
- onPointerEnter={(event) => {
- if (edgeMode === 'head-trim') {
- setHovered(true);
- setAltKey(event.altKey);
- }
-
- onHover(
- edgeMode === 'head-trim' && event.altKey && rollingEnabled
- ? 'rolling'
- : edgeMode,
- );
- }}
+ onPointerEnter={() => onHover(edgeMode)}
onPointerLeave={onLeave}
onPointerDown={onPointerDown}
onClick={(e) => e.stopPropagation()}
/>
) : null}
- {secondaryAction ? (
+ {secondaryAction && handleLayout.secondary !== null ? (
<div
role="separator"
aria-orientation="vertical"
@@ -3216,8 +3133,8 @@ export const useTimelineSequenceFromDrag = ({
const TimelineSequenceRightEdgeDragHandleInner: React.FC<{
readonly cursor: string;
readonly isTransitionSeries: boolean;
- readonly transitionStartOffset: number | null;
- readonly touchingNext: boolean;
+ readonly handleLeft: number;
+ readonly edgeOffset: number;
readonly onHoverEnd: () => void;
readonly nodePathInfo: SequenceNodePathInfo;
readonly mediaDurationDragLimits: TimelineSequenceMediaDurationDragLimits | null;
@@ -3236,8 +3153,8 @@ const TimelineSequenceRightEdgeDragHandleInner: React.FC<{
}> = ({
cursor,
isTransitionSeries,
- transitionStartOffset,
- touchingNext,
+ handleLeft,
+ edgeOffset,
onHoverEnd,
nodePathInfo,
mediaDurationDragLimits,
@@ -3429,10 +3346,7 @@ const TimelineSequenceRightEdgeDragHandleInner: React.FC<{
const propStatuses = propStatusesRef.current;
const handleRect = captureTarget.getBoundingClientRect();
const initialEdgeClientX =
- transitionStartOffset !== null
- ? handleRect.left + TRANSITION_RIGHT_HANDLE_INSET
- : (captureTarget.parentElement?.getBoundingClientRect().right ??
- handleRect.right - HANDLE_OUTSET);
+ captureTarget.parentElement!.getBoundingClientRect().left + edgeOffset;
const initialEdgeClientY = handleRect.top;
const initialTimelineEdge = latestRef.current.initialEdgeFrame;
@@ -3671,7 +3585,7 @@ const TimelineSequenceRightEdgeDragHandleInner: React.FC<{
sequencesRef,
timelineDurationInFrames,
windowWidth,
- transitionStartOffset,
+ edgeOffset,
isTransitionSeries,
updateSnapFrameRef,
],
@@ -3686,30 +3600,10 @@ const TimelineSequenceRightEdgeDragHandleInner: React.FC<{
const style: React.CSSProperties = {
...baseStyle,
- // Keep the outgoing trim inside the solid clip, clear of the incoming edge.
- zIndex: isTransitionSeries ? 2 : baseStyle.zIndex,
- left:
- transitionStartOffset !== null
- ? transitionStartOffset - TRANSITION_RIGHT_HANDLE_INSET
- : undefined,
- right:
- transitionStartOffset !== null
- ? undefined
- : isTransitionSeries
- ? 0
- : touchingNext
- ? 'min(2px, 12.5%)'
- : -HANDLE_OUTSET,
- width:
- transitionStartOffset !== null
- ? baseStyle.width
- : isTransitionSeries
- ? TRANSITION_CLIP_EDGE_WIDTH
- : touchingNext
- ? 'min(10px, 12.5%)'
- : baseStyle.width,
+ left: handleLeft,
cursor,
background: TRANSPARENT,
+ pointerEvents: 'auto',
};
return (
diff --git a/packages/studio/src/components/Timeline/get-timeline-transition-neighbors.ts b/packages/studio/src/components/Timeline/get-timeline-transition-neighbors.ts
index 54816e39df..6e39bd835a 100644
--- a/packages/studio/src/components/Timeline/get-timeline-transition-neighbors.ts
+++ b/packages/studio/src/components/Timeline/get-timeline-transition-neighbors.ts
@@ -21,6 +21,18 @@ export const getTimelineTransitionNeighbors = ({
(item) => item.timelineOrder,
);
const index = siblings.findIndex((item) => item.id === sequenceId);
+ const previousClip = siblings[index - 1];
+ if (
+ sequence.timelineTrack.role === 'clip' &&
+ previousClip?.timelineTrack?.role === 'clip' &&
+ previousClip.duration > 0 &&
+ sequence.duration > 0 &&
+ Math.abs(previousClip.from + previousClip.duration - sequence.from) <
+ 0.000001
+ ) {
+ return {previous: previousClip, next: sequence};
+ }
+
const transitionIndex =
sequence.timelineTrack.role === 'transition' ? index : index - 1;
const previous = siblings[transitionIndex - 1];
diff --git a/packages/studio/src/components/Timeline/get-timeline-trim-handle-layout.ts b/packages/studio/src/components/Timeline/get-timeline-trim-handle-layout.ts
new file mode 100644
index 0000000000..37b330651c
--- /dev/null
+++ b/packages/studio/src/components/Timeline/get-timeline-trim-handle-layout.ts
@@ -0,0 +1,58 @@
+export const TIMELINE_TRIM_HANDLE_WIDTH = 8;
+
+export const getTimelineTrimHandleLayout = ({
+ leftEdge,
+ rightEdge,
+ rolling,
+ leftTrim,
+ secondary,
+ rightTrim,
+ nextRolling,
+ activeEdge,
+}: {
+ readonly leftEdge: number;
+ readonly rightEdge: number;
+ readonly rolling: boolean;
+ readonly leftTrim: boolean;
+ readonly secondary: boolean;
+ readonly rightTrim: boolean;
+ readonly nextRolling: boolean;
+ readonly activeEdge: 'left' | 'right' | 'source-only' | null;
+}) => {
+ const width = TIMELINE_TRIM_HANDLE_WIDTH;
+ // The roll owns the cut; each adjoining trim stays on its own side.
+ const rollingLeft = leftEdge - width / 2;
+ const leftTrimLeft = leftEdge + (rolling ? width / 2 : 0);
+ const secondaryLeft = leftTrimLeft + (leftTrim ? width : 0);
+ const rightTrimLeft = rightEdge - width - (nextRolling ? width / 2 : 0);
+ const availableEnd = rightEdge - (nextRolling ? width / 2 : 0);
+ const rightTrimFits = rightTrim && rightTrimLeft >= leftTrimLeft;
+ const leftActionsEnd = rightTrimFits ? rightTrimLeft : availableEnd;
+ // Keep the wide-clip positions. Source trimming historically requires 32px;
+ // narrower clips lose actions rather than shrinking or repacking their targets.
+ // Keep a captured handle mounted if the drag itself makes its clip too narrow.
+ return {
+ rolling:
+ rolling && (rightEdge - leftEdge >= width || activeEdge === 'left')
+ ? rollingLeft
+ : null,
+ leftTrim:
+ leftTrim &&
+ (leftTrimLeft + width <= leftActionsEnd ||
+ activeEdge === 'left' ||
+ activeEdge === 'source-only')
+ ? leftTrimLeft
+ : null,
+ secondary:
+ secondary &&
+ ((rightEdge - leftEdge >= 32 &&
+ secondaryLeft + width <= leftActionsEnd) ||
+ activeEdge === 'source-only')
+ ? secondaryLeft
+ : null,
+ rightTrim:
+ rightTrim && (rightTrimFits || activeEdge === 'right')
+ ? rightTrimLeft
+ : null,
+ };
+};
diff --git a/packages/studio/src/components/Timeline/use-timeline-sequence-registry.ts b/packages/studio/src/components/Timeline/use-timeline-sequence-registry.ts
index f6481c94d1..d119b16d9f 100644
--- a/packages/studio/src/components/Timeline/use-timeline-sequence-registry.ts
+++ b/packages/studio/src/components/Timeline/use-timeline-sequence-registry.ts
@@ -80,6 +80,25 @@ export const useTimelineSequenceRegistry = (sequenceId: string) => {
string,
{previous: TSequence | null; next: TSequence | null}
>();
+ for (const clip of sequences) {
+ const adjacent = adjacentById.get(clip.id);
+ if (!adjacent) continue;
+ touchingById.set(clip.id, {
+ previous:
+ adjacent.previous &&
+ Math.abs(
+ adjacent.previous.from + adjacent.previous.duration - clip.from,
+ ) < 0.000001
+ ? adjacent.previous
+ : null,
+ next:
+ adjacent.next &&
+ Math.abs(clip.from + clip.duration - adjacent.next.from) < 0.000001
+ ? adjacent.next
+ : null,
+ });
+ }
+
const normalTrackIds = new Set(
sequences
.filter(