Skip to content

Open source CapCut alternative.

TypeScript

fix(site): a timeline drop hands the skimmer and the keyboard to the editor

David Lec55ddf2dd101
diff --git a/site/src/cut/components/Timeline.tsx b/site/src/cut/components/Timeline.tsx
index 5f518192..38351486 100644
--- a/site/src/cut/components/Timeline.tsx
+++ b/site/src/cut/components/Timeline.tsx
@@ -45,7 +45,7 @@ import {
import { originalSettings, type ExportDoc } from "@/cut/lib/exportClient";
import { useExports } from "@/cut/lib/exportStore";
import { isDragActive, startDrag, subscribeDragActive } from "@/cut/lib/drag";
-import { shortcutDecline } from "@/cut/lib/shortcutGate";
+import { keyboardToEditor, shortcutDecline } from "@/cut/lib/shortcutGate";
import { additiveClick } from "@/cut/lib/hostKeys";
import { CLIP_GAP, laneDragFor, laneDragParts, startLaneMove, startLaneTrim, type LaneDrag, type LaneKind } from "@/cut/lib/laneTracks";
import { downloadMedia, ensurePeaks, importImage, importStockMusic, importStockVideo, peekEdgeFrame, requestEdgeFrame, revealMedia, stripFailedFor, subscribeStripStatus } from "@/cut/lib/media";
@@ -3282,6 +3282,23 @@ function HoverLine({
}) {
const skimTime = useSkim();
useEffect(() => () => setSkim(null), []);
+ // A drag fires no pointer events, so a drop leaves the pointer over the
+ // timeline with the skimmer wherever it was before the drag began. The drop
+ // is the pointer's position: the skimmer moves there, so ⌘B cuts the clip
+ // that just landed, and the keyboard comes to the editor with it.
+ useEffect(() => {
+ const el = scrollRef.current;
+ if (!el) return;
+ const land = (e: DragEvent) => {
+ const inner = innerRef.current;
+ if (!inner) return;
+ const t = (e.clientX - inner.getBoundingClientRect().left) / useEditor.getState().pxPerSec;
+ if (!hold) setSkim(Math.max(0, t));
+ keyboardToEditor();
+ };
+ el.addEventListener("drop", land, { capture: true });
+ return () => el.removeEventListener("drop", land, { capture: true });
+ }, [scrollRef, innerRef, hold]);
useEffect(() => {
const el = scrollRef.current;
if (!el || hold) return;
diff --git a/site/src/cut/lib/shortcutGate.ts b/site/src/cut/lib/shortcutGate.ts
index 460c209b..bca62165 100644
--- a/site/src/cut/lib/shortcutGate.ts
+++ b/site/src/cut/lib/shortcutGate.ts
@@ -65,6 +65,17 @@ export const isPasteTarget = (el: EventTarget | null): boolean =>
el instanceof HTMLElement &&
(el.tagName === "INPUT" || el.tagName === "TEXTAREA" || el.isContentEditable);
+/**
+ * Hand the keyboard to the editor. A gesture on the editor's own surface — a
+ * drop on the timeline — is where the person's attention is now, so a text
+ * field still holding the focus from before it lets go. A drop moves no focus
+ * on its own, and a composer left focused swallows every ⌫ and ⌘B that follows.
+ */
+export function keyboardToEditor(): void {
+ const el = document.activeElement;
+ if (isTextEntry(el)) (el as HTMLElement).blur();
+}
+
/**
* Whether a dialog stands over the editor, which owns the keyboard while it is
* open. A popup keeps its element through its exit animation, and on a machine