fix: keyframe drag bug

This commit is contained in:
Maze Winther
2026-03-02 15:06:31 +01:00
parent 9261589ff3
commit 887d1795dd
@@ -9,7 +9,10 @@ import { useEditor } from "@/hooks/use-editor";
import { useKeyframeSelection } from "./use-keyframe-selection"; import { useKeyframeSelection } from "./use-keyframe-selection";
import { snapTimeToFrame } from "@/lib/time"; import { snapTimeToFrame } from "@/lib/time";
import { timelineTimeToSnappedPixels } from "@/lib/timeline"; import { timelineTimeToSnappedPixels } from "@/lib/timeline";
import { DRAG_THRESHOLD_PX, TIMELINE_CONSTANTS } from "@/constants/timeline-constants"; import {
DRAG_THRESHOLD_PX,
TIMELINE_CONSTANTS,
} from "@/constants/timeline-constants";
import { RetimeKeyframeCommand } from "@/lib/commands/timeline/element/keyframes/retime-keyframe"; import { RetimeKeyframeCommand } from "@/lib/commands/timeline/element/keyframes/retime-keyframe";
import { BatchCommand } from "@/lib/commands"; import { BatchCommand } from "@/lib/commands";
import type { SelectedKeyframeRef } from "@/types/animation"; import type { SelectedKeyframeRef } from "@/types/animation";
@@ -44,6 +47,7 @@ export function useKeyframeDrag({
const { const {
selectedKeyframes, selectedKeyframes,
isKeyframeSelected, isKeyframeSelected,
setKeyframeSelection,
toggleKeyframeSelection, toggleKeyframeSelection,
selectKeyframeRange, selectKeyframeRange,
} = useKeyframeSelection(); } = useKeyframeSelection();
@@ -196,6 +200,11 @@ export function useKeyframeDrag({
const anySelected = keyframes.some((keyframe) => const anySelected = keyframes.some((keyframe) =>
isKeyframeSelected({ keyframe }), isKeyframeSelected({ keyframe }),
); );
if (!anySelected) {
setKeyframeSelection({ keyframes });
}
const keyframeRefsToTrack = anySelected ? selectedKeyframes : keyframes; const keyframeRefsToTrack = anySelected ? selectedKeyframes : keyframes;
pendingDragRef.current = { pendingDragRef.current = {
@@ -204,7 +213,7 @@ export function useKeyframeDrag({
}; };
setIsPendingDrag(true); setIsPendingDrag(true);
}, },
[isKeyframeSelected, selectedKeyframes], [isKeyframeSelected, selectedKeyframes, setKeyframeSelection],
); );
const handleKeyframeClick = useCallback( const handleKeyframeClick = useCallback(