From e6bfd999a2aadfcd83aebcc2329fdfa522082bb1 Mon Sep 17 00:00:00 2001 From: Aria Minaei Date: Tue, 3 Aug 2021 12:17:10 +0200 Subject: [PATCH] Keyframe drag snapping --- .../BasicKeyframedTrack/KeyframeEditor/Dot.tsx | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/theatre/studio/src/panels/SequenceEditorPanel/DopeSheet/Right/BasicKeyframedTrack/KeyframeEditor/Dot.tsx b/theatre/studio/src/panels/SequenceEditorPanel/DopeSheet/Right/BasicKeyframedTrack/KeyframeEditor/Dot.tsx index c2261e3..98fc2d3 100644 --- a/theatre/studio/src/panels/SequenceEditorPanel/DopeSheet/Right/BasicKeyframedTrack/KeyframeEditor/Dot.tsx +++ b/theatre/studio/src/panels/SequenceEditorPanel/DopeSheet/Right/BasicKeyframedTrack/KeyframeEditor/Dot.tsx @@ -118,6 +118,7 @@ function useDragKeyframe(node: HTMLDivElement | null, props: IProps) { let toUnitSpace: SequenceEditorPanelLayout['scaledSpace']['toUnitSpace'] let tempTransaction: CommitOrDiscard | undefined let propsAtStartOfDrag: IProps + let startingLayout: SequenceEditorPanelLayout let selectionDragHandlers: | ReturnType @@ -148,21 +149,21 @@ function useDragKeyframe(node: HTMLDivElement | null, props: IProps) { selectionDragHandlers.onDrag(dx, dy, event) return } - const delta = toUnitSpace(dx) + const original = + propsAtStartOfDrag.trackData.keyframes[propsAtStartOfDrag.index] + const deltaPos = toUnitSpace(dx) + const newPosBeforeSnapping = Math.max(original.position + deltaPos, 0) if (tempTransaction) { tempTransaction.discard() tempTransaction = undefined } tempTransaction = getStudio()!.tempTransaction(({stateEditors}) => { - stateEditors.coreByProject.historic.sheetsById.sequence.transformKeyframes( + stateEditors.coreByProject.historic.sheetsById.sequence.replaceKeyframes( { ...propsAtStartOfDrag.leaf.sheetObject.address, trackId: propsAtStartOfDrag.leaf.trackId, - keyframeIds: [propsAtStartOfDrag.keyframe.id], - translate: delta, - scale: 1, - origin: 0, + keyframes: [{...original, position: newPosBeforeSnapping}], }, ) })