summaryrefslogtreecommitdiff
path: root/apps/web/src/hooks/timeline/element/use-element-interaction.ts
diff options
context:
space:
mode:
Diffstat (limited to 'apps/web/src/hooks/timeline/element/use-element-interaction.ts')
-rw-r--r--apps/web/src/hooks/timeline/element/use-element-interaction.ts40
1 files changed, 17 insertions, 23 deletions
diff --git a/apps/web/src/hooks/timeline/element/use-element-interaction.ts b/apps/web/src/hooks/timeline/element/use-element-interaction.ts
index c92d6722..79f1272c 100644
--- a/apps/web/src/hooks/timeline/element/use-element-interaction.ts
+++ b/apps/web/src/hooks/timeline/element/use-element-interaction.ts
@@ -7,10 +7,15 @@ import {
type RefObject,
} from "react";
import { useEditor } from "@/hooks/use-editor";
+import { useShiftKey } from "@/hooks/use-shift-key";
import { useElementSelection } from "@/hooks/timeline/element/use-element-selection";
-import { TIMELINE_CONSTANTS } from "@/constants/timeline-constants";
+import {
+ DRAG_THRESHOLD_PX,
+ TIMELINE_CONSTANTS,
+} from "@/constants/timeline-constants";
import { snapTimeToFrame } from "@/lib/time";
import { computeDropTarget } from "@/lib/timeline/drop-utils";
+import { getMouseTimeFromClientX } from "@/lib/timeline/drag-utils";
import { generateUUID } from "@/utils/id";
import { useTimelineSnapping } from "@/hooks/timeline/use-timeline-snapping";
import type {
@@ -21,8 +26,6 @@ import type {
} from "@/types/timeline";
import type { SnapPoint } from "@/hooks/timeline/use-timeline-snapping";
-const DRAG_THRESHOLD_PX = 5;
-
interface UseElementInteractionProps {
zoomLevel: number;
timelineRef: RefObject<HTMLDivElement | null>;
@@ -54,24 +57,6 @@ interface PendingDragState {
clickOffsetTime: number;
}
-function getMouseTimeFromClientX({
- clientX,
- containerRect,
- zoomLevel,
- scrollLeft,
-}: {
- clientX: number;
- containerRect: DOMRect;
- zoomLevel: number;
- scrollLeft: number;
-}): number {
- const mouseX = clientX - containerRect.left + scrollLeft;
- return Math.max(
- 0,
- mouseX / (TIMELINE_CONSTANTS.PIXELS_PER_SECOND * zoomLevel),
- );
-}
-
function getClickOffsetTime({
clientX,
elementRect,
@@ -175,6 +160,7 @@ export function useElementInteraction({
onSnapPointChange,
}: UseElementInteractionProps) {
const editor = useEditor();
+ const isShiftHeldRef = useShiftKey();
const tracks = editor.timeline.getTracks();
const { snapElementEdge } = useTimelineSnapping();
const {
@@ -230,7 +216,8 @@ export function useElementInteraction({
frameSnappedTime: number;
movingElement: TimelineElement | null | undefined;
}) => {
- if (!snappingEnabled || !movingElement) {
+ const shouldSnap = snappingEnabled && !isShiftHeldRef.current;
+ if (!shouldSnap || !movingElement) {
return { snappedTime: frameSnappedTime, snapPoint: null };
}
@@ -268,7 +255,14 @@ export function useElementInteraction({
snapPoint: snapResult.snapPoint,
};
},
- [snappingEnabled, editor.playback, snapElementEdge, tracks, zoomLevel],
+ [
+ snappingEnabled,
+ editor.playback,
+ snapElementEdge,
+ tracks,
+ zoomLevel,
+ isShiftHeldRef,
+ ],
);
useEffect(() => {