Skip to content

The open-source CapCut alternative

Merge branch 'feat/shortcut-actions' into staging

Maze Winther74e7d427aaed
diff --cc apps/web/src/components/keyboard-shortcuts-help.tsx
index a48b3c21,c40e5eb4..0481b1dd
--- a/apps/web/src/components/keyboard-shortcuts-help.tsx
+++ b/apps/web/src/components/keyboard-shortcuts-help.tsx
@@@ -1,7 -1,5 +1,6 @@@
"use client";
+import { useKeyboardShortcuts } from "@/hooks/use-keyboard-shortcuts";
- import { Keyboard } from "lucide-react";
import { useState } from "react";
import { Button } from "./ui/button";
import {
@@@ -12,33 -10,48 +11,40 @@@
DialogTitle,
DialogTrigger,
} from "./ui/dialog";
+import { getPlatformSpecialKey } from "@/lib/utils";
+ import { Badge } from "./ui/badge";
+ import { Keyboard, Settings } from "lucide-react";
+ import {
+ useKeyboardShortcutsHelp,
+ KeyboardShortcut,
+ } from "@/hooks/use-keyboard-shortcuts-help";
+ import { KeybindingEditor } from "./keybinding-editor";
-const KeyBadge = ({ keyName }: { keyName: string }) => {
- // Replace common key names with symbols or friendly names
- const displayKey = keyName
- .replace("Cmd", "⌘")
- .replace("Shift", "Shift")
- .replace("ArrowLeft", "Arrow Left")
- .replace("ArrowRight", "Arrow Right")
- .replace("ArrowUp", "Arrow Up")
- .replace("ArrowDown", "Arrow Down")
- .replace("←", "◀")
- .replace("→", "▶")
- .replace("Space", "Space");
-
- return (
- <Badge variant="secondary" className="font-mono text-xs px-1 py-1">
- {displayKey}
- </Badge>
- );
+const modifier: {
+ [key: string]: string;
+} = {
+ Shift: "Shift",
+ Alt: "Alt",
+ ArrowLeft: "←",
+ ArrowRight: "→",
+ ArrowUp: "↑",
+ ArrowDown: "↓",
+ Space: "Space",
};
+function getKeyWithModifier(key: string) {
+ if (key === "Ctrl") return getPlatformSpecialKey();
+ return modifier[key] || key;
+}
+
- const ShortcutItem = ({ shortcut }: { shortcut: any }) => {
+ const ShortcutItem = ({ shortcut }: { shortcut: KeyboardShortcut }) => {
// Filter out lowercase duplicates for display - if both "j" and "J" exist, only show "J"
const displayKeys = shortcut.keys.filter((key: string) => {
- const lowerKey = key.toLowerCase();
- const upperKey = key.toUpperCase();
-
- // If this is a lowercase letter and the uppercase version exists, skip it
if (
- key === lowerKey &&
- key !== upperKey &&
- shortcut.keys.includes(upperKey)
- ) {
+ key.includes("Cmd") &&
+ shortcut.keys.includes(key.replace("Cmd", "Ctrl"))
+ )
return false;
- }
return true;
});
@@@ -119,17 -166,3 +156,17 @@@ export const KeyboardShortcutsHelp = (
</Dialog>
);
};
+
+function ShortcutKey({ children }: { children: React.ReactNode }) {
+ return (
- <kbd
++ <kbd
+ className="inline-flex font-sans text-xs rounded px-2 min-w-[1.5rem] min-h-[1.5rem] leading-none items-center justify-center shadow-sm border mr-1"
+ style={{
+ backgroundColor: "rgba(0, 0, 0, 0.2)",
- borderColor: "rgba(255, 255, 255, 0.1)"
++ borderColor: "rgba(255, 255, 255, 0.1)",
+ }}
+ >
+ {children}
+ </kbd>
+ );
- };
++}
diff --cc apps/web/src/lib/utils.ts
index fd47cc13,188ec261..8d2ee03a
--- a/apps/web/src/lib/utils.ts
+++ b/apps/web/src/lib/utils.ts
@@@ -44,6 -44,26 +44,25 @@@ export function generateUUID(): string
);
}
+ export function isDOMElement(el: any): el is HTMLElement {
+ return !!el && (el instanceof Element || el instanceof HTMLElement);
+ }
+
+ export function isTypableElement(el: HTMLElement): boolean {
+ // If content editable, then it is editable
+ if (el.isContentEditable) return true;
+
+ // If element is an input and the input is enabled, then it is typable
+ if (el.tagName === "INPUT") {
+ return !(el as HTMLInputElement).disabled;
+ }
+ // If element is a textarea and the input is enabled, then it is typable
+ if (el.tagName === "TEXTAREA") {
+ return !(el as HTMLTextAreaElement).disabled;
+ }
+
+ return false;
+ }
-
export function isAppleDevice() {
return /(Mac|iPhone|iPod|iPad)/i.test(navigator.platform);
}