Skip to content

🎥 Make videos programmatically with React

@remotion/studio: Add rolling edits for touching timeline clips

Jonny Burger73a9dd4dbba1
diff --git a/packages/studio/src/components/Timeline/TimelineSequence.tsx b/packages/studio/src/components/Timeline/TimelineSequence.tsx
index 1c07432ac6..7ec7eba7e1 100644
--- a/packages/studio/src/components/Timeline/TimelineSequence.tsx
+++ b/packages/studio/src/components/Timeline/TimelineSequence.tsx
@@ -81,10 +81,12 @@ import {splitSelectedTimelineItems} from './split-selected-timeline-item';
import {getTimelineAssetLinkInfo} from './timeline-asset-link';
import {timelineLeftEdgeCursor} from './timeline-left-edge-cursor';
import {timelineLayerLayoutsRef} from './timeline-refs';
+import {timelineRightEdgeCursor} from './timeline-right-edge-cursor';
import {
PACKED_LABEL_BOTTOM,
TimelineSequenceLabel,
} from './timeline-sequence-label';
+import {timelineSourceOnlyCursor} from './timeline-source-only-cursor';
import {
TIMELINE_PACKED_AUXILIARY_ROW_HEIGHT,
TIMELINE_PACKED_TRACK_HEIGHT,
@@ -114,6 +116,7 @@ import {
isTimelineSequenceDurationDraggable,
isTimelineSequenceLeftEdgeDraggable,
TimelineSequenceLeftEdgeDragHandle,
+ type TimelineSequenceLeftEdgeDragMode,
TimelineSequenceMediaDurationDragLimitsContext,
TimelineSequenceRightEdgeDragHandle,
useTimelineSequenceFromDrag,
@@ -136,16 +139,20 @@ const MIN_SECONDARY_LEFT_EDGE_ACTION_WIDTH = 32;
type TimelineEdgeHighlightEdge = 'left' | 'right' | 'source-only';
-type TimelineEdgeHighlight = {
- readonly nodePathKey: string;
+type TimelineEdgeHighlightState = {
readonly edge: TimelineEdgeHighlightEdge;
+ readonly isDragging: boolean;
+};
+
+type TimelineEdgeHighlight = TimelineEdgeHighlightState & {
+ readonly nodePathKey: string;
};
const TimelineEdgeHighlightContext = React.createContext<{
readonly register: (
nodePathKey: string,
listener: React.Dispatch<
- React.SetStateAction<TimelineEdgeHighlightEdge | null>
+ React.SetStateAction<TimelineEdgeHighlightState | null>
>,
) => () => void;
readonly setHighlights: (
@@ -159,11 +166,11 @@ export const TimelineEdgeHighlightProvider: React.FC<{
// Keep the context value stable so highlighting boundaries does not re-render
// every timeline sequence through a context broadcast.
const value = useMemo(() => {
- let highlights = new Map<string, TimelineEdgeHighlightEdge>();
+ let highlights = new Map<string, TimelineEdgeHighlightState>();
const listeners = new Map<
string,
Set<
- React.Dispatch<React.SetStateAction<TimelineEdgeHighlightEdge | null>>
+ React.Dispatch<React.SetStateAction<TimelineEdgeHighlightState | null>>
>
>();
@@ -171,7 +178,7 @@ export const TimelineEdgeHighlightProvider: React.FC<{
register: (
nodePathKey: string,
listener: React.Dispatch<
- React.SetStateAction<TimelineEdgeHighlightEdge | null>
+ React.SetStateAction<TimelineEdgeHighlightState | null>
>,
) => {
const listenersForNodePath = listeners.get(nodePathKey) ?? new Set();
@@ -189,10 +196,7 @@ export const TimelineEdgeHighlightProvider: React.FC<{
},
setHighlights: (nextHighlights: readonly TimelineEdgeHighlight[]) => {
const nextHighlightMap = new Map(
- nextHighlights.map((highlight) => [
- highlight.nodePathKey,
- highlight.edge,
- ]),
+ nextHighlights.map((highlight) => [highlight.nodePathKey, highlight]),
);
const changedNodePathKeys = new Set([
...highlights.keys(),
@@ -201,7 +205,10 @@ export const TimelineEdgeHighlightProvider: React.FC<{
for (const nodePathKey of changedNodePathKeys) {
const previousEdge = highlights.get(nodePathKey) ?? null;
const nextEdge = nextHighlightMap.get(nodePathKey) ?? null;
- if (previousEdge !== nextEdge) {
+ if (
+ previousEdge?.edge !== nextEdge?.edge ||
+ previousEdge?.isDragging !== nextEdge?.isDragging
+ ) {
for (const listener of listeners.get(nodePathKey) ?? []) {
listener(nextEdge);
}
@@ -468,11 +475,8 @@ const TimelineSequenceBar: React.FC<{
? style.background
: `linear-gradient(to ${activeTrimEdge === 'left' ? 'right' : 'left'}, #00E500 0 2px, #00E50000 2px), ${style.background ?? TRANSPARENT}`;
- const actualStyle: React.CSSProperties = useMemo(() => {
+ const sceneClippingStyle: React.CSSProperties = useMemo(() => {
return {
- ...style,
- background: TRANSPARENT,
- opacity: 1,
maskImage:
s.timelineTrack?.role === 'clip' && frameIncrement !== null
? getTimelineSceneMask({
@@ -495,6 +499,16 @@ const TimelineSequenceBar: React.FC<{
sceneRight,
]);
+ const actualStyle: React.CSSProperties = useMemo(
+ () => ({
+ ...style,
+ background: TRANSPARENT,
+ opacity: 1,
+ pointerEvents: 'none',
+ }),
+ [style],
+ );
+
const premountIndicator = premount ? (
<div
style={{
@@ -665,76 +679,86 @@ const TimelineSequenceBar: React.FC<{
onPointerDown={selectable ? onPointerDown : undefined}
onClick={onClick ?? undefined}
>
- {negativeStart ? (
- <>
- <TimelineSequenceNegativeStart
- left={negativeStart.left}
- width={negativeStart.width}
- leftEdgeVisible={leftEdgeVisible}
- clipped={negativeStartClipped}
- />
- <div
- style={{
- background: sequenceBackground,
- borderBottomLeftRadius: 0,
- borderBottomRightRadius: style.borderBottomRightRadius,
- borderTopLeftRadius: 0,
- borderTopRightRadius: style.borderTopRightRadius,
- boxSizing: 'border-box',
- height: '100%',
- left: negativeStartEnd,
- overflow: 'hidden',
- position: 'absolute',
- top: 0,
- width: `calc(100% - ${negativeStartEnd + visualRightInset}px)`,
- }}
- >
+ {/* Clip the paint to its scene, while keeping seam handles outside it hittable. */}
+ <div
+ style={{
+ position: 'absolute',
+ inset: 0,
+ ...sceneClippingStyle,
+ pointerEvents: 'auto',
+ }}
+ >
+ {negativeStart ? (
+ <>
+ <TimelineSequenceNegativeStart
+ left={negativeStart.left}
+ width={negativeStart.width}
+ leftEdgeVisible={leftEdgeVisible}
+ clipped={negativeStartClipped}
+ />
<div
style={{
+ background: sequenceBackground,
+ borderBottomLeftRadius: 0,
+ borderBottomRightRadius: style.borderBottomRightRadius,
+ borderTopLeftRadius: 0,
+ borderTopRightRadius: style.borderTopRightRadius,
+ boxSizing: 'border-box',
height: '100%',
- left: -negativeStartEnd,
+ left: negativeStartEnd,
+ overflow: 'hidden',
position: 'absolute',
top: 0,
- width: `calc(100% + ${negativeStartEnd}px)`,
+ width: `calc(100% - ${negativeStartEnd + visualRightInset}px)`,
}}
>
- {content}
+ <div
+ style={{
+ height: '100%',
+ left: -negativeStartEnd,
+ position: 'absolute',
+ top: 0,
+ width: `calc(100% + ${negativeStartEnd}px)`,
+ }}
+ >
+ {content}
+ </div>
</div>
+ </>
+ ) : (
+ <div
+ style={{
+ position: 'absolute',
+ inset: 0,
+ right: visualRightInset,
+ background: sequenceBackground,
+ overflow: 'hidden',
+ borderRadius: 'inherit',
+ }}
+ >
+ {content}
</div>
- </>
- ) : (
- <div
- style={{
- position: 'absolute',
- inset: 0,
- right: visualRightInset,
- background: sequenceBackground,
- overflow: 'hidden',
- borderRadius: 'inherit',
- }}
- >
- {content}
- </div>
- )}
- {(selected || containsSelection) && selectionBounds ? (
- <div
- aria-hidden="true"
- style={{
- position: 'absolute',
- inset: 0,
- left: selectionBounds.left,
- right: Math.max(
- visualRightInset,
- Number(style.width) -
- selectionBounds.left -
- selectionBounds.width,
- ),
- borderRadius: 'inherit',
- boxShadow: `inset 0 0 0 2px ${WHITE}`,
- pointerEvents: 'none',
- }}
- />
- ) : null}
+ )}
+ {(selected || containsSelection) && selectionBounds ? (
+ <div
+ aria-hidden="true"
+ style={{
+ position: 'absolute',
+ inset: 0,
+ left: selectionBounds.left,
+ right: Math.max(
+ visualRightInset,
+ Number(style.width) -
+ selectionBounds.left -
+ selectionBounds.width,
+ ),
+ borderRadius: 'inherit',
+ boxShadow: `inset 0 0 0 2px ${WHITE}`,
+ pointerEvents: 'none',
+ }}
+ />
+ ) : null}
+ </div>
<div style={{pointerEvents: 'auto'}}>{edgeDragHandles}</div>
</div>
);
@@ -770,8 +794,10 @@ const useTimelineSequenceState = (props: TimelineSequenceProps) => {
() => createDragAwareDoubleClickTracker(),
[],
);
- const [activeEdgeHighlight, setActiveEdgeHighlight] =
- useState<TimelineEdgeHighlightEdge | null>(null);
+ const [edgeHighlight, setEdgeHighlight] =
+ useState<TimelineEdgeHighlightState | null>(null);
+ const activeEdgeHighlight = edgeHighlight?.edge ?? null;
+ const isEdgeDragging = edgeHighlight?.isDragging ?? false;
const activeTrimEdge =
activeEdgeHighlight === 'source-only' ? 'left' : activeEdgeHighlight;
useEffect(() => {
@@ -781,21 +807,26 @@ const useTimelineSequenceState = (props: TimelineSequenceProps) => {
return edgeHighlightController?.register(
stringifySequenceSubscriptionKey(nodePath),
- setActiveEdgeHighlight,
+ setEdgeHighlight,
);
}, [edgeHighlightController, nodePath]);
const naturalSequenceDuration = useTimelineSequenceNaturalDuration({
sequenceId: s.id,
- enabled:
- activeEdgeHighlight !== null && activeEdgeHighlight !== 'source-only',
+ enabled: isEdgeDragging && activeEdgeHighlight !== 'source-only',
});
const previousCascadingSequenceId = registryEntry?.previousSequenceId ?? null;
const previousCascadingOverrideId = registryEntry?.previousOverrideId ?? null;
const nextCascadingOverrideId = registryEntry?.nextOverrideId ?? null;
+ const previousTouchingSequence =
+ registryEntry?.previousTouchingSequence ?? null;
+ const nextTouchingSequence = registryEntry?.nextTouchingSequence ?? null;
+ const previousTouchingOverrideId =
+ previousTouchingSequence?.controls?.overrideId ?? null;
const startEdgeDrag = useCallback(
(
edge: TimelineEdgeHighlightEdge,
highlightAdjacent: boolean,
+ isDragging: boolean,
targetNodePaths: readonly SequencePropsSubscriptionKey[],
) => {
if (targetNodePaths.length === 0) {
@@ -811,7 +842,7 @@ const useTimelineSequenceState = (props: TimelineSequenceProps) => {
if (highlightAdjacent) {
const adjacentOverrideId =
edge === 'left'
- ? previousCascadingOverrideId
+ ? (previousCascadingOverrideId ?? previousTouchingOverrideId)
: nextCascadingOverrideId;
const adjacentNodePath = adjacentOverrideId
? overrideIdToNodePathMappingsRef.current[adjacentOverrideId]
@@ -832,11 +863,13 @@ const useTimelineSequenceState = (props: TimelineSequenceProps) => {
[...highlights].map(([nodePathKey, highlightEdge]) => ({
nodePathKey,
edge: highlightEdge,
+ isDragging,
})),
);
},
[
previousCascadingOverrideId,
+ previousTouchingOverrideId,
nextCascadingOverrideId,
overrideIdToNodePathMappingsRef,
edgeHighlightController,
@@ -844,21 +877,28 @@ const useTimelineSequenceState = (props: TimelineSequenceProps) => {
);
const startLeftEdgeDrag = useCallback(
(
- mode: 'ripple' | 'source-only' | 'self-trim',
+ mode: TimelineSequenceLeftEdgeDragMode,
+ isDragging: boolean,
targetNodePaths: readonly SequencePropsSubscriptionKey[],
) =>
startEdgeDrag(
mode === 'source-only' ? 'source-only' : 'left',
- mode === 'ripple',
+ mode === 'ripple' || mode === 'rolling',
+ isDragging,
targetNodePaths,
),
[startEdgeDrag],
);
const startRightEdgeDrag = useCallback(
- (targetNodePaths: readonly SequencePropsSubscriptionKey[]) =>
- startEdgeDrag('right', true, targetNodePaths),
+ (
+ isDragging: boolean,
+ targetNodePaths: readonly SequencePropsSubscriptionKey[],
+ ) => startEdgeDrag('right', true, isDragging, targetNodePaths),
[startEdgeDrag],
);
+ const clearEdgeHighlight = useCallback(() => {
+ edgeHighlightController?.setHighlights([]);
+ }, [edgeHighlightController]);
const endEdgeDrag = useCallback(
(wasDragged: boolean) => {
edgeHighlightController?.setHighlights([]);
@@ -1459,6 +1499,24 @@ const useTimelineSequenceState = (props: TimelineSequenceProps) => {
: previousCascadingSequenceId !== null
? previousCascadingSequenceCanResize
: fromCanUpdate && durationCanUpdate && trimBeforeCanUpdate);
+ const previousTouchingNodePath = previousTouchingOverrideId
+ ? overrideIdToNodePathMappingsRef.current[previousTouchingOverrideId]
+ : null;
+ const rollingEnabled = 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',
+ );
const hasCaptionsSchema = Object.values(s.controls?.schema ?? {}).some(
(field) => field.type === 'remotion-captions',
);
@@ -1466,12 +1524,17 @@ const useTimelineSequenceState = (props: TimelineSequenceProps) => {
props,
video,
dragAwareDoubleClick,
+ isEdgeDragging,
activeEdgeHighlight,
activeTrimEdge,
naturalSequenceDuration,
startLeftEdgeDrag,
startRightEdgeDrag,
endEdgeDrag,
+ clearEdgeHighlight,
+ rollingEnabled,
+ previousTouchingSequence,
+ nextTouchingSequence,
extendVideoLastFrame,
mediaStartFrame,
mediaLoopStartFrame,
@@ -1542,12 +1605,17 @@ const TimelineSequenceLayoutInner: React.FC<{
const {
video,
dragAwareDoubleClick,
+ isEdgeDragging,
activeEdgeHighlight,
activeTrimEdge,
naturalSequenceDuration,
startLeftEdgeDrag,
startRightEdgeDrag,
endEdgeDrag,
+ clearEdgeHighlight,
+ rollingEnabled,
+ previousTouchingSequence,
+ nextTouchingSequence,
extendVideoLastFrame,
mediaStartFrame,
mediaLoopStartFrame,
@@ -1705,6 +1773,7 @@ const TimelineSequenceLayoutInner: React.FC<{
: getTimelineLayerHeight(s.type);
const trimOutline = (() => {
if (
+ !isEdgeDragging ||
activeEdgeHighlight === null ||
activeEdgeHighlight === 'source-only' ||
s.loopDisplay ||
@@ -1824,6 +1893,7 @@ const TimelineSequenceLayoutInner: React.FC<{
borderBottomRightRadius: showRightBorderRadius ? 2 : 0,
position: 'absolute',
isolation: s.timelineTrack ? 'isolate' : undefined,
+ zIndex: rollingEnabled ? 2 : undefined,
height: layerHeight,
top: s.timelineTrack ? 0 : undefined,
marginLeft: visibleLayout?.marginLeft ?? 0,
@@ -1836,6 +1906,7 @@ const TimelineSequenceLayoutInner: React.FC<{
hasCaptionsSchema,
s.type,
s.timelineTrack,
+ rollingEnabled,
showLeftBorderRadius,
showRightBorderRadius,
visibleLayout,
@@ -1923,8 +1994,25 @@ const TimelineSequenceLayoutInner: React.FC<{
<TimelineSequenceLeftEdgeDragHandle
cursor={`${timelineTrimEdgeCursor}, ew-resize`}
trimBeforeCursor={`${timelineLeftEdgeCursor}, e-resize`}
+ sourceOnlyCursor={`${timelineSourceOnlyCursor}, ew-resize`}
edgeEnabled={showLeftEdgeDragHandle}
- edgeMode={isFirstCascadingSequence ? 'source-only' : 'ripple'}
+ edgeMode={
+ isFirstCascadingSequence
+ ? 'source-only'
+ : isCascadingSequence(s)
+ ? 'ripple'
+ : 'self-trim'
+ }
+ rollingEnabled={rollingEnabled}
+ rollingOutset={Math.min(
+ 2,
+ ((previousTouchingSequence?.duration ?? 0) /
+ keyframePlaybackRate) *
+ frameIncrement *
+ 0.125,
+ )}
+ touchingPrevious={previousTouchingSequence !== null}
+ onHoverEnd={clearEdgeHighlight}
secondaryAction={secondaryLeftEdgeAction}
nodePathInfo={nodePathInfo}
windowWidth={windowWidth}
@@ -1943,7 +2031,9 @@ const TimelineSequenceLayoutInner: React.FC<{
nodePathInfo &&
validatedLocation ? (
<TimelineSequenceRightEdgeDragHandle
- cursor={`${timelineTrimEdgeCursor}, ew-resize`}
+ touchingNext={nextTouchingSequence !== null}
+ onHoverEnd={clearEdgeHighlight}
+ cursor={`${isCascadingSequence(s) ? timelineTrimEdgeCursor : timelineRightEdgeCursor}, ew-resize`}
nodePathInfo={nodePathInfo}
mediaDurationDragLimits={mediaDurationDragLimits}
windowWidth={windowWidth}
diff --git a/packages/studio/src/components/Timeline/TimelineSequenceRightEdgeDragHandle.tsx b/packages/studio/src/components/Timeline/TimelineSequenceRightEdgeDragHandle.tsx
index d64e717966..1a9b7c11c9 100644
--- a/packages/studio/src/components/Timeline/TimelineSequenceRightEdgeDragHandle.tsx
+++ b/packages/studio/src/components/Timeline/TimelineSequenceRightEdgeDragHandle.tsx
@@ -80,6 +80,12 @@ const LEFT_EDGE_HANDLE_OUTSET = 4;
const timelineSequenceEdgeDragThresholdPx = 4;
export const timelineSequenceFromDragSnapThresholdPx = 10;
+export type TimelineSequenceLeftEdgeDragMode =
+ | 'ripple'
+ | 'source-only'
+ | 'self-trim'
+ | 'rolling';
+
export type TimelineSequenceMediaDurationDragLimits = {
readonly initialDuration: number;
readonly maximumDuration: number;
@@ -250,6 +256,7 @@ export type TimelineSequenceLeftEdgeDragTarget = {
readonly nodePath: SequencePropsSubscriptionKey;
readonly playbackRate: number;
readonly positionField: 'from' | null;
+ // Series trims resize the previous clip; positioned Track clips roll both edges.
readonly ripplePrevious: TimelineSequenceDurationDragTarget | null;
readonly timingLimits: ReturnType<
typeof getTimelineSequenceTimingLimits
@@ -551,7 +558,20 @@ const getTimelineSequenceLeftEdgeDragValuesForTarget = ({
readonly deltaFrames: number;
readonly trimBeforeOnly: boolean;
}) => {
- const localDeltaFrames = deltaFrames * target.parentPlaybackRate;
+ // Track rolling edits share one delta so neither edge can clamp independently.
+ const previous = target.positionField !== null ? target.ripplePrevious : null;
+ const sharedDeltaFrames = previous
+ ? Math.max(
+ (previous.minimumDuration - previous.initialDuration) /
+ previous.parentPlaybackRate,
+ Math.min(
+ (previous.maximumDuration - previous.initialDuration) /
+ previous.parentPlaybackRate,
+ deltaFrames,
+ ),
+ )
+ : deltaFrames;
+ const localDeltaFrames = sharedDeltaFrames * target.parentPlaybackRate;
// Only trims that started inside the parent are constrained to its start.
// Source-only and cascading trims do not change `from`.
let clampedDeltaFrames =
@@ -599,37 +619,42 @@ export const getTimelineSequenceLeftEdgeDragChanges = ({
readonly trimBeforeOnly?: boolean;
}): SaveSequencePropChange[] => {
return targets.flatMap((target) => {
+ const nextValues = getTimelineSequenceLeftEdgeDragValuesForTarget({
+ target,
+ deltaFrames,
+ trimBeforeOnly,
+ });
+ const changes: SaveSequencePropChange[] = [];
if (target.ripplePrevious && !trimBeforeOnly) {
const previous = target.ripplePrevious;
+ const appliedDelta =
+ target.positionField === null
+ ? deltaFrames
+ : (nextValues.from - target.initialFrom) / target.parentPlaybackRate;
const nextDuration = getTimelineSequenceDurationDragValue({
initialDuration: previous.initialDuration,
- deltaFrames: deltaFrames * previous.parentPlaybackRate,
+ deltaFrames: appliedDelta * previous.parentPlaybackRate,
maximumDuration: previous.maximumDuration,
minimumDuration: previous.minimumDuration,
});
- return nextDuration === previous.initialDuration
- ? []
- : [
- {
- fileName: previous.fileName,
- nodePath: previous.nodePath,
- fieldKey: previous.endField.fieldKey,
- value: getTimelineSequenceEndFieldValue({
- endField: previous.endField,
- durationInFrames: nextDuration,
- }),
- defaultValue: null,
- schema: previous.schema,
- },
- ];
- }
+ if (nextDuration !== previous.initialDuration) {
+ changes.push({
+ fileName: previous.fileName,
+ nodePath: previous.nodePath,
+ fieldKey: previous.endField.fieldKey,
+ value: getTimelineSequenceEndFieldValue({
+ endField: previous.endField,
+ durationInFrames: nextDuration,
+ }),
+ defaultValue: null,
+ schema: previous.schema,
+ });
+ }
- const nextValues = getTimelineSequenceLeftEdgeDragValuesForTarget({
- target,
- deltaFrames,
- trimBeforeOnly,
- });
- const changes: SaveSequencePropChange[] = [];
+ if (target.positionField === null) {
+ return changes;
+ }
+ }
if (
target.positionField !== null &&
@@ -1342,6 +1367,152 @@ export const getTimelineSequenceLeftEdgeDragTargets = ({
return [...targets.values()];
};
+export const getTimelineSequenceRollingEditTargets = ({
+ draggedNodePathInfo,
+ sequences,
+ overrideIdsToNodePaths,
+ propStatuses,
+ timelineDurationInFrames,
+ mediaDurationDragLimits,
+}: {
+ readonly draggedNodePathInfo: SequenceNodePathInfo;
+ readonly sequences: TSequence[];
+ readonly overrideIdsToNodePaths: OverrideIdToNodePaths;
+ readonly propStatuses: PropStatuses;
+ readonly timelineDurationInFrames: number;
+ readonly mediaDurationDragLimits: ReadonlyMap<
+ string,
+ TimelineSequenceMediaDurationDragLimits | null
+ > | null;
+}): TimelineSequenceLeftEdgeDragTarget[] | null => {
+ const tracks = calculateTimeline({sequences, overrideIdsToNodePaths});
+ const rightTrack = findSequenceTrack({
+ tracks,
+ nodePathInfo: draggedNodePathInfo,
+ });
+ if (
+ !rightTrack ||
+ rightTrack.sequence.timelineTrack?.role !== 'clip' ||
+ !tracks.some(
+ (track) =>
+ track.sequence.timelineTrack?.id ===
+ rightTrack.sequence.timelineTrack?.id &&
+ track.sequence.controls?.componentIdentity ===
+ 'dev.remotion.remotion.Track',
+ )
+ ) {
+ return null;
+ }
+
+ const leftTrack = tracks.find(
+ (track) =>
+ track.sequence.timelineTrack?.id ===
+ rightTrack.sequence.timelineTrack?.id &&
+ track.sequence.timelineTrack?.role === 'clip' &&
+ track.sequence.id !== rightTrack.sequence.id &&
+ track.sequence.parent === rightTrack.sequence.parent &&
+ track.sequence.duration > 0 &&
+ Math.abs(
+ track.sequence.from +
+ track.sequence.duration -
+ rightTrack.sequence.from,
+ ) < 0.000001,
+ );
+ if (
+ !leftTrack?.nodePathInfo ||
+ leftTrack.sequence.loopDisplay ||
+ rightTrack.sequence.loopDisplay ||
+ leftTrack.sequence.frozenFrame !== null ||
+ rightTrack.sequence.frozenFrame !== null ||
+ ('frozenMediaFrame' in leftTrack.sequence &&
+ leftTrack.sequence.frozenMediaFrame !== null) ||
+ ('frozenMediaFrame' in rightTrack.sequence &&
+ rightTrack.sequence.frozenMediaFrame !== null) ||
+ !isTimelineSequenceDurationDraggable(leftTrack.sequence)
+ ) {
+ return null;
+ }
+
+ const right = getTimelineSequenceLeftEdgeDragTargets({
+ draggedNodePathInfo,
+ selectedItems: [],
+ sequences,
+ overrideIdsToNodePaths,
+ propStatuses,
+ timelineDurationInFrames,
+ trimBeforeOnly: false,
+ rippleEdit: false,
+ })?.[0];
+ const left = getTimelineSequenceDurationDragTargets({
+ draggedNodePathInfo: leftTrack.nodePathInfo,
+ draggedSequenceMediaDurationDragLimits:
+ mediaDurationDragLimits?.get(
+ getTimelineSequenceSelectionKey(leftTrack.nodePathInfo),
+ ) ?? null,
+ selectedSequenceMediaDurationDragLimits: mediaDurationDragLimits,
+ selectedItems: [],
+ sequences,
+ overrideIdsToNodePaths,
+ propStatuses,
+ timelineDurationInFrames,
+ })?.[0];
+ if (
+ !right ||
+ !left ||
+ right.positionField === null ||
+ stringifySequenceSubscriptionKey(right.nodePath) ===
+ stringifySequenceSubscriptionKey(left.nodePath)
+ ) {
+ return null;
+ }
+
+ const movingSequenceIds = new Set([
+ leftTrack.sequence.id,
+ rightTrack.sequence.id,
+ ]);
+ const leftLimits = getTimelineSequenceTimingLimits({
+ track: leftTrack,
+ tracks,
+ sequences,
+ timelineDurationInFrames,
+ movingSequenceIds,
+ propStatuses,
+ });
+ const naturalDuration = getTimelineSequenceNaturalDuration({
+ sequence: sequences.find(
+ (sequence) => sequence.id === leftTrack.sequence.id,
+ )!,
+ sequences,
+ });
+ const mediaLimits = mediaDurationDragLimits?.get(
+ getTimelineSequenceSelectionKey(leftTrack.nodePathInfo),
+ );
+ const maximumDuration = Math.min(
+ leftLimits.maximumDuration,
+ mediaLimits
+ ? mediaLimits.maximumDuration * leftTrack.keyframePlaybackRate
+ : Infinity,
+ naturalDuration ?? Infinity,
+ );
+ return [
+ {
+ ...right,
+ ripplePrevious: {
+ ...left,
+ maximumDuration: Math.max(left.initialDuration, maximumDuration),
+ },
+ timingLimits: getTimelineSequenceTimingLimits({
+ track: rightTrack,
+ tracks,
+ sequences,
+ timelineDurationInFrames,
+ movingSequenceIds,
+ propStatuses,
+ }),
+ },
+ ];
+};
+
export const getTimelineSequenceFromDragTargets = ({
draggedNodePathInfo,
selectedItems,
@@ -1593,8 +1764,13 @@ const clearFromDragOverrides = ({
const TimelineSequenceLeftEdgeDragHandleInner: React.FC<{
readonly cursor: string;
readonly trimBeforeCursor: string;
+ readonly sourceOnlyCursor: string;
readonly edgeEnabled: boolean;
- readonly edgeMode: 'ripple' | 'source-only';
+ readonly edgeMode: 'ripple' | 'source-only' | 'self-trim';
+ readonly rollingEnabled: boolean;
+ readonly rollingOutset: number;
+ readonly touchingPrevious: boolean;
+ readonly onHoverEnd: () => void;
readonly secondaryAction: 'source-only' | 'self-trim' | null;
readonly nodePathInfo: SequenceNodePathInfo;
readonly windowWidth: number;
@@ -1602,7 +1778,8 @@ const TimelineSequenceLeftEdgeDragHandleInner: React.FC<{
readonly initialEdgeFrame: number;
readonly fps: number;
readonly onDragStart: (
- mode: 'ripple' | 'source-only' | 'self-trim',
+ mode: TimelineSequenceLeftEdgeDragMode,
+ isDragging: boolean,
targetNodePaths: readonly SequencePropsSubscriptionKey[],
) => void;
readonly onDragEnd: (wasDragged: boolean) => void;
@@ -1611,8 +1788,13 @@ const TimelineSequenceLeftEdgeDragHandleInner: React.FC<{
}> = ({
cursor,
trimBeforeCursor,
+ sourceOnlyCursor,
edgeEnabled,
edgeMode,
+ rollingEnabled,
+ rollingOutset,
+ touchingPrevious,
+ onHoverEnd,
secondaryAction,
nodePathInfo,
windowWidth,
@@ -1636,6 +1818,9 @@ const TimelineSequenceLeftEdgeDragHandleInner: React.FC<{
OverrideIdToNodePathMappingsRefContext,
);
const {previewServerState} = useContext(StudioServerConnectionCtx);
+ const mediaDurationDragLimitsRegistry = useContext(
+ TimelineSequenceMediaDurationDragLimitsContext,
+ );
const currentSelection = useCurrentTimelineSelectionStateAsRef();
const [trimTooltip, setTrimTooltip] =
useState<TimelineTrimTooltipState | null>(null);
@@ -1652,7 +1837,7 @@ const TimelineSequenceLeftEdgeDragHandleInner: React.FC<{
pointerId: number;
selectionInteraction: TimelineSelectionInteraction | null;
targets: readonly TimelineSequenceLeftEdgeDragTarget[];
- mode: 'ripple' | 'source-only' | 'self-trim';
+ mode: TimelineSequenceLeftEdgeDragMode;
} | null>(null);
const latestRef = useRef({
@@ -1729,21 +1914,25 @@ const TimelineSequenceLeftEdgeDragHandleInner: React.FC<{
setPropStatuses: latestSetPropStatuses,
clientId: latestServerState.clientId,
undoLabel:
- dragState.mode === 'source-only'
- ? dragState.targets.length > 1
- ? 'Adjust source start of selected sequences'
- : 'Adjust source start'
- : dragState.targets.length > 1
- ? 'Resize selected sequences'
- : 'Resize sequence',
+ dragState.mode === 'rolling'
+ ? 'Roll edit'
+ : dragState.mode === 'source-only'
+ ? dragState.targets.length > 1
+ ? 'Adjust source start of selected sequences'
+ : 'Adjust source start'
+ : dragState.targets.length > 1
+ ? 'Resize selected sequences'
+ : 'Resize sequence',
redoLabel:
- dragState.mode === 'source-only'
- ? dragState.targets.length > 1
- ? 'Adjust source start of selected sequences back'
- : 'Adjust source start back'
- : dragState.targets.length > 1
- ? 'Resize selected sequences back'
- : 'Resize sequence back',
+ dragState.mode === 'rolling'
+ ? 'Roll edit back'
+ : dragState.mode === 'source-only'
+ ? dragState.targets.length > 1
+ ? 'Adjust source start of selected sequences back'
+ : 'Adjust source start back'
+ : dragState.targets.length > 1
+ ? 'Resize selected sequences back'
+ : 'Resize sequence back',
});
savePromise
@@ -1769,13 +1958,20 @@ const TimelineSequenceLeftEdgeDragHandleInner: React.FC<{
}
const mode =
- e.currentTarget.dataset.trimMode === 'source-only'
- ? 'source-only'
- : e.currentTarget.dataset.trimMode === 'self-trim'
- ? 'self-trim'
- : 'ripple';
+ e.currentTarget.dataset.trimMode === 'rolling'
+ ? 'rolling'
+ : e.currentTarget.dataset.trimMode === 'source-only'
+ ? 'source-only'
+ : e.currentTarget.dataset.trimMode === 'self-trim'
+ ? 'self-trim'
+ : 'ripple';
const trimBeforeOnly = mode === 'source-only';
- const activeCursor = mode === 'ripple' ? cursor : trimBeforeCursor;
+ const activeCursor =
+ mode === 'ripple' || mode === 'rolling'
+ ? cursor
+ : mode === 'source-only'
+ ? sourceOnlyCursor
+ : trimBeforeCursor;
e.stopPropagation();
e.preventDefault();
@@ -1796,16 +1992,26 @@ const TimelineSequenceLeftEdgeDragHandleInner: React.FC<{
const {nodePathInfo: latestNodePathInfo} = latestRef.current;
const {selectedItems: latestSelectedItems} = currentSelection.current;
const targets = canCalculateDelta
- ? (getTimelineSequenceLeftEdgeDragTargets({
- draggedNodePathInfo: latestNodePathInfo,
- selectedItems: latestSelectedItems,
- sequences: sequencesRef.current,
- overrideIdsToNodePaths: overrideIdToNodePathMappingsRef.current,
- propStatuses: propStatusesRef.current,
- timelineDurationInFrames,
- trimBeforeOnly,
- rippleEdit: mode === 'ripple',
- }) ?? [])
+ ? ((mode === 'rolling'
+ ? getTimelineSequenceRollingEditTargets({
+ draggedNodePathInfo: latestNodePathInfo,
+ sequences: sequencesRef.current,
+ overrideIdsToNodePaths: overrideIdToNodePathMappingsRef.current,
+ propStatuses: propStatusesRef.current,
+ timelineDurationInFrames,
+ mediaDurationDragLimits:
+ mediaDurationDragLimitsRegistry?.current ?? null,
+ })
+ : getTimelineSequenceLeftEdgeDragTargets({
+ draggedNodePathInfo: latestNodePathInfo,
+ selectedItems: latestSelectedItems,
+ sequences: sequencesRef.current,
+ overrideIdsToNodePaths: overrideIdToNodePathMappingsRef.current,
+ propStatuses: propStatusesRef.current,
+ timelineDurationInFrames,
+ trimBeforeOnly,
+ rippleEdit: mode === 'ripple',
+ })) ?? [])
: [];
const draggedKey = stringifySequenceSubscriptionKey(
latestNodePathInfo.sequenceSubscriptionKey,
@@ -1815,13 +2021,15 @@ const TimelineSequenceLeftEdgeDragHandleInner: React.FC<{
stringifySequenceSubscriptionKey(target.nodePath) === draggedKey,
);
const handleRect = e.currentTarget.getBoundingClientRect();
- const initialEdgeClientX = handleRect.left + HANDLE_OUTSET;
+ const initialEdgeClientX =
+ e.currentTarget.parentElement!.getBoundingClientRect().left;
const initialEdgeClientY = handleRect.top;
const initialTimelineEdge = latestRef.current.initialEdgeFrame;
stopPointerSessionRef.current?.();
onDragStart(
mode,
+ true,
targets.map((target) => target.nodePath),
);
dragStateRef.current = {
@@ -1850,7 +2058,8 @@ const TimelineSequenceLeftEdgeDragHandleInner: React.FC<{
const dx = pointerEvent.clientX - dragState.initialClientX;
const pointerDeltaFrames = Math.round(dx / dragState.pxPerFrame);
const deltaFrames =
- dragState.mode === 'self-trim'
+ dragState.mode === 'self-trim' &&
+ draggedTarget?.positionField === null
? -pointerDeltaFrames
: pointerDeltaFrames;
dragState.latestDeltaFrames = deltaFrames;
@@ -1882,7 +2091,16 @@ const TimelineSequenceLeftEdgeDragHandleInner: React.FC<{
const previous = target.ripplePrevious;
const nextDuration = getTimelineSequenceDurationDragValue({
initialDuration: previous.initialDuration,
- deltaFrames: deltaFrames * previous.parentPlaybackRate,
+ deltaFrames:
+ (target.positionField === null
+ ? deltaFrames
+ : (getTimelineSequenceLeftEdgeDragValuesForTarget({
+ target,
+ deltaFrames,
+ trimBeforeOnly: false,
+ }).from -
+ target.initialFrom) /
+ target.parentPlaybackRate) * previous.parentPlaybackRate,
maximumDuration: previous.maximumDuration,
minimumDuration: previous.minimumDuration,
});
@@ -1900,7 +2118,9 @@ const TimelineSequenceLeftEdgeDragHandleInner: React.FC<{
durationInFrames: previous.initialDuration,
}),
});
- continue;
+ if (target.positionField === null) {
+ continue;
+ }
}
const nextValues = getTimelineSequenceLeftEdgeDragValuesForTarget({
@@ -1964,7 +2184,17 @@ const TimelineSequenceLeftEdgeDragHandleInner: React.FC<{
if (ripplePrevious) {
const nextDuration = getTimelineSequenceDurationDragValue({
initialDuration: ripplePrevious.initialDuration,
- deltaFrames: deltaFrames * ripplePrevious.parentPlaybackRate,
+ deltaFrames:
+ (draggedTarget.positionField === null
+ ? deltaFrames
+ : (getTimelineSequenceLeftEdgeDragValuesForTarget({
+ target: draggedTarget,
+ deltaFrames,
+ trimBeforeOnly: false,
+ }).from -
+ draggedTarget.initialFrom) /
+ draggedTarget.parentPlaybackRate) *
+ ripplePrevious.parentPlaybackRate,
maximumDuration: ripplePrevious.maximumDuration,
minimumDuration: ripplePrevious.minimumDuration,
});
@@ -1981,7 +2211,8 @@ const TimelineSequenceLeftEdgeDragHandleInner: React.FC<{
dragState.mode === 'source-only'
? (values.trimBefore - draggedTarget.initialTrimBefore) /
draggedTarget.playbackRate
- : values.from - draggedTarget.initialFrom;
+ : (values.from - draggedTarget.initialFrom) /
+ draggedTarget.parentPlaybackRate;
}
const edgeDelta =
@@ -1994,10 +2225,7 @@ const TimelineSequenceLeftEdgeDragHandleInner: React.FC<{
setTrimTooltip({
deltaFrames: appliedDelta,
edgeFrame: initialTimelineEdge + edgeDelta,
- x:
- initialEdgeClientX +
- (edgeDelta / draggedTarget.parentPlaybackRate) *
- dragState.pxPerFrame,
+ x: initialEdgeClientX + edgeDelta * dragState.pxPerFrame,
y: initialEdgeClientY,
});
}
@@ -2042,6 +2270,7 @@ const TimelineSequenceLeftEdgeDragHandleInner: React.FC<{
},
[
currentSelection,
+ mediaDurationDragLimitsRegistry,
overrideIdToNodePathMappingsRef,
cursor,
finishDrag,
@@ -2051,6 +2280,7 @@ const TimelineSequenceLeftEdgeDragHandleInner: React.FC<{
sequencesRef,
timelineDurationInFrames,
trimBeforeCursor,
+ sourceOnlyCursor,
windowWidth,
],
);
@@ -2064,23 +2294,73 @@ const TimelineSequenceLeftEdgeDragHandleInner: React.FC<{
const edgeStyle: React.CSSProperties = {
...baseStyle,
- left: -LEFT_EDGE_HANDLE_OUTSET,
- width: `calc(${LEFT_EDGE_HANDLE_OUTSET}px + min(${LEFT_EDGE_HANDLE_INSET}px, 12.5%))`,
- cursor: edgeMode === 'source-only' ? trimBeforeCursor : cursor,
+ left: rollingEnabled
+ ? 'min(2px, 12.5%)'
+ : touchingPrevious
+ ? 0
+ : -LEFT_EDGE_HANDLE_OUTSET,
+ width:
+ rollingEnabled || touchingPrevious
+ ? 'min(10px, 12.5%)'
+ : `calc(${LEFT_EDGE_HANDLE_OUTSET}px + min(${LEFT_EDGE_HANDLE_INSET}px, 12.5%))`,
+ cursor:
+ edgeMode === 'ripple'
+ ? cursor
+ : edgeMode === 'source-only'
+ ? sourceOnlyCursor
+ : trimBeforeCursor,
background: TRANSPARENT,
pointerEvents: 'auto',
};
const trimBeforeStyle: React.CSSProperties = {
...baseStyle,
- left: edgeEnabled ? 'min(4px, 12.5%)' : 0,
+ left: edgeEnabled
+ ? rollingEnabled
+ ? 'calc(min(2px, 12.5%) + min(10px, 12.5%))'
+ : touchingPrevious
+ ? 'min(10px, 12.5%)'
+ : 'min(4px, 12.5%)'
+ : 0,
width: edgeEnabled ? 'min(10px, 12.5%)' : 'min(14px, 25%)',
- cursor: trimBeforeCursor,
+ cursor:
+ secondaryAction === 'source-only' ? sourceOnlyCursor : trimBeforeCursor,
background: TRANSPARENT,
pointerEvents: 'auto',
};
+ const onHover = (mode: TimelineSequenceLeftEdgeDragMode) => {
+ if (dragStateRef.current === null) {
+ onDragStart(mode, false, [nodePathInfo.sequenceSubscriptionKey]);
+ }
+ };
+
+ const onLeave = () => {
+ if (dragStateRef.current === null) {
+ onHoverEnd();
+ }
+ };
return (
<>
+ {rollingEnabled ? (
+ <div
+ role="separator"
+ aria-orientation="vertical"
+ aria-label="Drag to roll edit"
+ data-trim-mode="rolling"
+ style={{
+ ...baseStyle,
+ left: -rollingOutset,
+ width: `calc(${rollingOutset}px + min(2px, 12.5%))`,
+ cursor,
+ background: TRANSPARENT,
+ pointerEvents: 'auto',
+ }}
+ onPointerEnter={() => onHover('rolling')}
+ onPointerLeave={onLeave}
+ onPointerDown={onPointerDown}
+ onClick={(e) => e.stopPropagation()}
+ />
+ ) : null}
{edgeEnabled ? (
<div
role="separator"
@@ -2092,6 +2372,8 @@ const TimelineSequenceLeftEdgeDragHandleInner: React.FC<{
}
data-trim-mode={edgeMode}
style={edgeStyle}
+ onPointerEnter={() => onHover(edgeMode)}
+ onPointerLeave={onLeave}
onPointerDown={onPointerDown}
onClick={(e) => e.stopPropagation()}
/>
@@ -2107,6 +2389,8 @@ const TimelineSequenceLeftEdgeDragHandleInner: React.FC<{
}
data-trim-mode={secondaryAction}
style={trimBeforeStyle}
+ onPointerEnter={() => onHover(secondaryAction)}
+ onPointerLeave={onLeave}
onPointerDown={onPointerDown}
onClick={(e) => e.stopPropagation()}
/>
@@ -2460,6 +2744,8 @@ export const useTimelineSequenceFromDrag = ({
const TimelineSequenceRightEdgeDragHandleInner: React.FC<{
readonly cursor: string;
+ readonly touchingNext: boolean;
+ readonly onHoverEnd: () => void;
readonly nodePathInfo: SequenceNodePathInfo;
readonly mediaDurationDragLimits: TimelineSequenceMediaDurationDragLimits | null;
readonly windowWidth: number;
@@ -2467,6 +2753,7 @@ const TimelineSequenceRightEdgeDragHandleInner: React.FC<{
readonly initialEdgeFrame: number;
readonly fps: number;
readonly onDragStart: (
+ isDragging: boolean,
targetNodePaths: readonly SequencePropsSubscriptionKey[],
) => void;
readonly onDragEnd: (wasDragged: boolean) => void;
@@ -2474,6 +2761,8 @@ const TimelineSequenceRightEdgeDragHandleInner: React.FC<{
readonly selected: boolean;
}> = ({
cursor,
+ touchingNext,
+ onHoverEnd,
nodePathInfo,
mediaDurationDragLimits,
windowWidth,
@@ -2670,12 +2959,17 @@ const TimelineSequenceRightEdgeDragHandleInner: React.FC<{
stringifySequenceSubscriptionKey(target.nodePath) === draggedKey,
);
const handleRect = e.currentTarget.getBoundingClientRect();
- const initialEdgeClientX = handleRect.right - HANDLE_OUTSET;
+ const initialEdgeClientX =
+ e.currentTarget.parentElement?.getBoundingClientRect().right ??
+ handleRect.right - HANDLE_OUTSET;
const initialEdgeClientY = handleRect.top;
const initialTimelineEdge = latestRef.current.initialEdgeFrame;
stopPointerSessionRef.current?.();
- onDragStart(targets.map((target) => target.nodePath));
+ onDragStart(
+ true,
+ targets.map((target) => target.nodePath),
+ );
dragStateRef.current = {
initialClientX: e.clientX,
latestDeltaFrames: 0,
@@ -2853,7 +3147,8 @@ const TimelineSequenceRightEdgeDragHandleInner: React.FC<{
const style: React.CSSProperties = {
...baseStyle,
- right: -HANDLE_OUTSET,
+ right: touchingNext ? 'min(2px, 12.5%)' : -HANDLE_OUTSET,
+ width: touchingNext ? 'min(10px, 12.5%)' : baseStyle.width,
cursor,
background: TRANSPARENT,
};
@@ -2865,6 +3160,16 @@ const TimelineSequenceRightEdgeDragHandleInner: React.FC<{
aria-orientation="vertical"
aria-label="Drag to change duration"
style={style}
+ onPointerEnter={() => {
+ if (dragStateRef.current === null) {
+ onDragStart(false, [nodePathInfo.sequenceSubscriptionKey]);
+ }
+ }}
+ onPointerLeave={() => {
+ if (dragStateRef.current === null) {
+ onHoverEnd();
+ }
+ }}
onPointerDown={onPointerDown}
onClick={(e) => e.stopPropagation()}
/>
diff --git a/packages/studio/src/components/Timeline/timeline-left-edge-cursor.ts b/packages/studio/src/components/Timeline/timeline-left-edge-cursor.ts
index e56f3204d6..44bc8a2d2e 100644
--- a/packages/studio/src/components/Timeline/timeline-left-edge-cursor.ts
+++ b/packages/studio/src/components/Timeline/timeline-left-edge-cursor.ts
@@ -1,6 +1,5 @@
const timelineLeftEdgeCursorSvg = `<svg width="24" height="24" viewBox="0 0 32 32" fill="none" xmlns="http://www.w3.org/2000/svg">
<g filter="url(#shadow)">
-<path d="M3 16L12 10V22L3 16Z" fill="black" stroke="white" stroke-width="1.5" stroke-linejoin="round"/>
<path d="M23 4.5H18C16.9 4.5 16 5.4 16 6.5V25.5C16 26.6 16.9 27.5 18 27.5H23" stroke="white" stroke-width="5" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M23 4.5H18C16.9 4.5 16 5.4 16 6.5V25.5C16 26.6 16.9 27.5 18 27.5H23" stroke="black" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"/>
</g>
@@ -11,4 +10,4 @@ const timelineLeftEdgeCursorSvg = `<svg width="24" height="24" viewBox="0 0 32 3
</defs>
</svg>`;
-export const timelineLeftEdgeCursor = `url("data:image/svg+xml,${encodeURIComponent(timelineLeftEdgeCursorSvg)}") 2.25 12`;
+export const timelineLeftEdgeCursor = `url("data:image/svg+xml,${encodeURIComponent(timelineLeftEdgeCursorSvg)}") 12 12`;
diff --git a/packages/studio/src/components/Timeline/timeline-right-edge-cursor.ts b/packages/studio/src/components/Timeline/timeline-right-edge-cursor.ts
index 904aacc961..afb67302d7 100644
--- a/packages/studio/src/components/Timeline/timeline-right-edge-cursor.ts
+++ b/packages/studio/src/components/Timeline/timeline-right-edge-cursor.ts
@@ -1,6 +1,5 @@
const timelineRightEdgeCursorSvg = `<svg width="24" height="24" viewBox="0 0 32 32" fill="none" xmlns="http://www.w3.org/2000/svg">
<g transform="translate(32 0) scale(-1 1)" filter="url(#shadow)">
-<path d="M3 16L12 10V22L3 16Z" fill="black" stroke="white" stroke-width="1.5" stroke-linejoin="round"/>
<path d="M23 4.5H18C16.9 4.5 16 5.4 16 6.5V25.5C16 26.6 16.9 27.5 18 27.5H23" stroke="white" stroke-width="5" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M23 4.5H18C16.9 4.5 16 5.4 16 6.5V25.5C16 26.6 16.9 27.5 18 27.5H23" stroke="black" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"/>
</g>
@@ -11,4 +10,4 @@ const timelineRightEdgeCursorSvg = `<svg width="24" height="24" viewBox="0 0 32
</defs>
</svg>`;
-export const timelineRightEdgeCursor = `url("data:image/svg+xml,${encodeURIComponent(timelineRightEdgeCursorSvg)}") 21.75 12`;
+export const timelineRightEdgeCursor = `url("data:image/svg+xml,${encodeURIComponent(timelineRightEdgeCursorSvg)}") 12 12`;
diff --git a/packages/studio/src/components/Timeline/timeline-source-only-cursor.ts b/packages/studio/src/components/Timeline/timeline-source-only-cursor.ts
new file mode 100644
index 0000000000..50fcd0d547
--- /dev/null
+++ b/packages/studio/src/components/Timeline/timeline-source-only-cursor.ts
@@ -0,0 +1,6 @@
+const timelineSourceOnlyCursorSvg = `<svg width="24" height="24" viewBox="0 0 32 32" fill="none" xmlns="http://www.w3.org/2000/svg">
+<path d="M5 6H3V26H5M27 6H29V26H27M8 16H24M8 16L12 12M8 16L12 20M24 16L20 12M24 16L20 20" stroke="white" stroke-width="5" stroke-linecap="round" stroke-linejoin="round"/>
+<path d="M5 6H3V26H5M27 6H29V26H27M8 16H24M8 16L12 12M8 16L12 20M24 16L20 12M24 16L20 20" stroke="black" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"/>
+</svg>`;
+
+export const timelineSourceOnlyCursor = `url("data:image/svg+xml,${encodeURIComponent(timelineSourceOnlyCursorSvg)}") 2.25 12`;
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 5896c3d734..f6481c94d1 100644
--- a/packages/studio/src/components/Timeline/use-timeline-sequence-registry.ts
+++ b/packages/studio/src/components/Timeline/use-timeline-sequence-registry.ts
@@ -15,6 +15,8 @@ type TimelineSequenceRegistryEntry = {
readonly previousSequenceId: string | null;
readonly previousOverrideId: string | null;
readonly nextOverrideId: string | null;
+ readonly previousTouchingSequence: TSequence | null;
+ readonly nextTouchingSequence: TSequence | null;
};
const indexedRegistries = new WeakMap<
@@ -74,6 +76,58 @@ export const useTimelineSequenceRegistry = (sequenceId: string) => {
}
}
+ const touchingById = new Map<
+ string,
+ {previous: TSequence | null; next: TSequence | null}
+ >();
+ const normalTrackIds = new Set(
+ sequences
+ .filter(
+ (sequence) =>
+ sequence.timelineTrack?.role === 'track' &&
+ sequence.controls?.componentIdentity ===
+ 'dev.remotion.remotion.Track',
+ )
+ .map((sequence) => sequence.timelineTrack!.id),
+ );
+ const clipsByTrack = new Map<string, TSequence[]>();
+ for (const sequence of sequences) {
+ if (
+ sequence.timelineTrack?.role !== 'clip' ||
+ !normalTrackIds.has(sequence.timelineTrack.id) ||
+ sequence.duration <= 0 ||
+ (!sequence.showInTimeline && sequence.type === 'sequence')
+ ) {
+ continue;
+ }
+
+ const clips = clipsByTrack.get(sequence.timelineTrack.id) ?? [];
+ clips.push(sequence);
+ clipsByTrack.set(sequence.timelineTrack.id, clips);
+ }
+
+ for (const clips of clipsByTrack.values()) {
+ clips.sort((a, b) => a.from - b.from);
+ for (let i = 0; i < clips.length; i++) {
+ const clip = clips[i];
+ const previousClip = clips[i - 1] ?? null;
+ const nextClip = clips[i + 1] ?? null;
+ touchingById.set(clip.id, {
+ previous:
+ previousClip?.parent === clip.parent &&
+ Math.abs(previousClip.from + previousClip.duration - clip.from) <
+ 0.000001
+ ? previousClip
+ : null,
+ next:
+ nextClip?.parent === clip.parent &&
+ Math.abs(clip.from + clip.duration - nextClip.from) < 0.000001
+ ? nextClip
+ : null,
+ });
+ }
+ }
+
const entries = new Map<string, TimelineSequenceRegistryEntry>();
for (const sequence of sequences) {
const adjacent = adjacentById.get(sequence.id);
@@ -81,15 +135,27 @@ export const useTimelineSequenceRegistry = (sequenceId: string) => {
const previousOverrideId =
adjacent?.previous?.controls?.overrideId ?? null;
const nextOverrideId = adjacent?.next?.controls?.overrideId ?? null;
+ const previousTouchingSequence =
+ touchingById.get(sequence.id)?.previous ?? null;
+ const nextTouchingSequence = touchingById.get(sequence.id)?.next ?? null;
const previousEntry = previous?.entries.get(sequence.id);
entries.set(
sequence.id,
previousEntry?.sequence === sequence &&
previousEntry.previousSequenceId === previousSequenceId &&
previousEntry.previousOverrideId === previousOverrideId &&
- previousEntry.nextOverrideId === nextOverrideId
+ previousEntry.nextOverrideId === nextOverrideId &&
+ previousEntry.previousTouchingSequence === previousTouchingSequence &&
+ previousEntry.nextTouchingSequence === nextTouchingSequence
? previousEntry
- : {sequence, previousSequenceId, previousOverrideId, nextOverrideId},
+ : {
+ sequence,
+ previousSequenceId,
+ previousOverrideId,
+ nextOverrideId,
+ previousTouchingSequence,
+ nextTouchingSequence,
+ },
);
}