Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

fix(desktop): make transcript video cuts reachable from the keyboard

Richie McIlroy786d693cadfa
diff --git a/apps/desktop/src/routes/editor/TranscriptPage.tsx b/apps/desktop/src/routes/editor/TranscriptPage.tsx
index de23250e2..41ab6a8b7 100644
--- a/apps/desktop/src/routes/editor/TranscriptPage.tsx
+++ b/apps/desktop/src/routes/editor/TranscriptPage.tsx
@@ -32,6 +32,7 @@ import { routeEditorPlaybackIntent } from "./playback-intent-routing";
import {
deleteTranscriptWords,
type FlatWord,
+ transcriptKeyAction,
transcriptSeekPosition,
} from "./transcript-edits";
@@ -605,7 +606,8 @@ function TranscriptWord(props: {
<button
type="button"
class="flex items-center justify-center gap-1 h-6 px-1.5 rounded-md bg-gray-11 text-white hover:bg-gray-10 transition-colors text-xs"
- title="Cut selected words and their video from the timeline"
+ title="Cut selected words and their video from the timeline (Shift+Delete)"
+ aria-keyshortcuts="Shift+Delete Shift+Backspace"
onClick={(e) => {
e.stopPropagation();
props.onCut();
@@ -703,36 +705,29 @@ function TranscriptEditor(props: {
const handleKeyDown = (e: KeyboardEvent) => {
if (editingIndex() !== -1) return;
const selected = selectedIndices();
- if (selected.size === 0) return;
+ const fromContainer = e.target === scrollContainerRef;
+ const action = transcriptKeyAction(e, selected.size, fromContainer);
+ if (!action) return;
+ e.preventDefault();
+ e.stopPropagation();
+ if (!fromContainer) scrollContainerRef?.focus({ preventScroll: true });
- if (e.key === "Enter" && selected.size === 1 && editingIndex() === -1) {
- e.preventDefault();
- e.stopPropagation();
+ if (action === "edit") {
const word = props.allWords[[...selected][0]];
if (word) startEditing(word);
- } else if (e.key === "Backspace" || e.key === "Delete") {
- e.preventDefault();
- e.stopPropagation();
- props.onDeleteWords([...selected]);
+ } else if (action === "delete" || action === "cut") {
+ if (action === "cut") props.onCutWords([...selected]);
+ else props.onDeleteWords([...selected]);
setSelectedIndices(new Set<number>());
setAnchorIndex(-1);
- } else if (e.key === "ArrowLeft") {
- e.preventDefault();
- e.stopPropagation();
- const minIdx = Math.min(...selected);
- const prev = Math.max(minIdx - 1, 0);
- setSelectedIndices(new Set([prev]));
- setAnchorIndex(prev);
- const word = props.allWords[prev];
- if (word) props.onWordClick(word);
- } else if (e.key === "ArrowRight") {
- e.preventDefault();
- e.stopPropagation();
- const maxIdx = Math.max(...selected);
- const next = Math.min(maxIdx + 1, props.allWords.length - 1);
- setSelectedIndices(new Set([next]));
- setAnchorIndex(next);
- const word = props.allWords[next];
+ } else {
+ const target =
+ action === "previous"
+ ? Math.max(Math.min(...selected) - 1, 0)
+ : Math.min(Math.max(...selected) + 1, props.allWords.length - 1);
+ setSelectedIndices(new Set([target]));
+ setAnchorIndex(target);
+ const word = props.allWords[target];
if (word) props.onWordClick(word);
}
};
@@ -796,6 +791,7 @@ function TranscriptEditor(props: {
else props.onDeleteWords(indices);
setSelectedIndices(new Set<number>());
setAnchorIndex(-1);
+ scrollContainerRef?.focus({ preventScroll: true });
};
const startEditing = (word: FlatWord) => {
diff --git a/apps/desktop/src/routes/editor/transcript-edits.test.ts b/apps/desktop/src/routes/editor/transcript-edits.test.ts
index 43eed9834..131c09de6 100644
--- a/apps/desktop/src/routes/editor/transcript-edits.test.ts
+++ b/apps/desktop/src/routes/editor/transcript-edits.test.ts
@@ -7,6 +7,7 @@ import type { EditorProjectConfiguration } from "./context";
import {
deleteTranscriptWords,
type FlatWord,
+ transcriptKeyAction,
transcriptSeekPosition,
} from "./transcript-edits";
@@ -165,3 +166,28 @@ describe("transcript seeking", () => {
expect(transcriptSeekPosition(1, 48, 13)).toBe(0);
});
});
+
+describe("transcript keyboard actions", () => {
+ const key = (key: string, shiftKey = false) => ({ key, shiftKey });
+
+ it("offers caption deletion and video cuts from the keyboard", () => {
+ for (const name of ["Backspace", "Delete"]) {
+ expect(transcriptKeyAction(key(name), 1, true)).toBe("delete");
+ expect(transcriptKeyAction(key(name, true), 1, true)).toBe("cut");
+ expect(transcriptKeyAction(key(name, true), 3, false)).toBe("cut");
+ }
+ });
+
+ it("leaves Enter to focused word action buttons", () => {
+ expect(transcriptKeyAction(key("Enter"), 1, true)).toBe("edit");
+ expect(transcriptKeyAction(key("Enter"), 1, false)).toBeNull();
+ expect(transcriptKeyAction(key("Enter"), 2, true)).toBeNull();
+ });
+
+ it("ignores keys without a selection", () => {
+ for (const name of ["Enter", "Backspace", "Delete", "ArrowLeft"]) {
+ expect(transcriptKeyAction(key(name, true), 0, true)).toBeNull();
+ }
+ expect(transcriptKeyAction(key(" "), 1, true)).toBeNull();
+ });
+});
diff --git a/apps/desktop/src/routes/editor/transcript-edits.ts b/apps/desktop/src/routes/editor/transcript-edits.ts
index 0e784d8b5..b100aeab1 100644
--- a/apps/desktop/src/routes/editor/transcript-edits.ts
+++ b/apps/desktop/src/routes/editor/transcript-edits.ts
@@ -139,3 +139,31 @@ export function transcriptSeekPosition(
? position
: Math.max(0, time - zoom / 2);
}
+
+export type TranscriptKeyAction =
+ | "edit"
+ | "delete"
+ | "cut"
+ | "previous"
+ | "next";
+
+export function transcriptKeyAction(
+ event: Pick<KeyboardEvent, "key" | "shiftKey">,
+ selectedCount: number,
+ fromContainer: boolean,
+): TranscriptKeyAction | null {
+ if (selectedCount === 0) return null;
+ switch (event.key) {
+ case "Enter":
+ return fromContainer && selectedCount === 1 ? "edit" : null;
+ case "Backspace":
+ case "Delete":
+ return event.shiftKey ? "cut" : "delete";
+ case "ArrowLeft":
+ return "previous";
+ case "ArrowRight":
+ return "next";
+ default:
+ return null;
+ }
+}