Record your screen, ship a demo. Free and open-source, GPU-accelerated, no watermarks, no subscriptions. Windows, macOS, Linux. Actively maintained.
TypeScript cross-platformelectronffmpegopen-sourceproduct-demorustscreen-capturescreen-recorderscreen-recordingscreen-studioscreencastspeech-to-texttypescriptvideo-editingvideo-editorwaylandwgpuwhisper
fix(editor): open the highlighted project on Enter in the Open project dialog
EtienneLescot720d6a994f62
diff --git a/src/components/ai-edition/Modals.tsx b/src/components/ai-edition/Modals.tsxindex f2b7bb7a8..062668d4d 100644--- a/src/components/ai-edition/Modals.tsx+++ b/src/components/ai-edition/Modals.tsx@@ -148,6 +148,44 @@ export function OpenProjectModal({if (!open) setConfirmId(null);}, [open]);const filtered = projects.filter((p) => p.title.toLowerCase().includes(query.toLowerCase()));+ // The row ↑↓ moved to, or null for the default: the open project, or the first match once a+ // search narrows the list. Enter opens it, as the footer says (#1135).+ const [cursor, setCursor] = useState<number | null>(null);+ // biome-ignore lint/correctness/useExhaustiveDependencies: a new search or a reopened dialog starts back at the default row.+ useEffect(() => setCursor(null), [query, open]);+ const defaultRow = query+ ? 0+ : Math.max(+ 0,+ filtered.findIndex((p) => p.id === activeProjectId),+ );+ const highlighted = Math.min(cursor ?? defaultRow, filtered.length - 1);+ const highlightedId = filtered[highlighted]?.id;+ const listRef = useRef<HTMLDivElement | null>(null);+ // biome-ignore lint/correctness/useExhaustiveDependencies: scroll each time the highlight moves.+ useEffect(() => {+ listRef.current+ ?.querySelector<HTMLElement>('[aria-current="true"]')+ ?.scrollIntoView?.({ block: "nearest" });+ }, [highlightedId]);+ useEffect(() => {+ if (!open) return;+ const onKeyDown = (event: KeyboardEvent) => {+ // A focused button (a row, its trash, Browse) answers Enter itself.+ if (confirmId || event.target instanceof HTMLButtonElement) return;+ if (event.key === "ArrowDown" || event.key === "ArrowUp") {+ event.preventDefault();+ const step = event.key === "ArrowDown" ? 1 : -1;+ setCursor(Math.max(0, Math.min(filtered.length - 1, highlighted + step)));+ } else if (event.key === "Enter" && highlightedId) {+ event.preventDefault();+ onSelect(highlightedId);+ onClose();+ }+ };+ document.addEventListener("keydown", onKeyDown);+ return () => document.removeEventListener("keydown", onKeyDown);+ }, [open, confirmId, filtered.length, highlighted, highlightedId, onSelect, onClose]);return (<ModalShellopen={open}@@ -168,6 +206,7 @@ export function OpenProjectModal({/></div><div+ ref={listRef}style={{display: "flex",flexDirection: "column",@@ -189,6 +228,7 @@ export function OpenProjectModal({) : (filtered.map((p) => {const isActive = p.id === activeProjectId;+ const isHighlighted = p.id === highlightedId;if (p.id === confirmId) {return (<div@@ -249,6 +289,7 @@ export function OpenProjectModal({<div key={p.id} style={{ display: "flex", alignItems: "center", gap: 4 }}><buttontype="button"+ aria-current={isHighlighted ? "true" : undefined}onClick={() => {onSelect(p.id);onClose();@@ -263,7 +304,7 @@ export function OpenProjectModal({padding: "10px 12px",border: "none",borderRadius: "var(--r-md)",- background: isActive ? "var(--accent-soft)" : "transparent",+ background: isHighlighted ? "var(--accent-soft)" : "transparent",boxShadow: isActive ? "inset 0 0 0 1px var(--accent)" : "none",color: "var(--fg)",cursor: "pointer",diff --git a/src/components/ai-edition/OpenProjectModal.test.tsx b/src/components/ai-edition/OpenProjectModal.test.tsxindex 88cdea8f5..ccc48c6db 100644--- a/src/components/ai-edition/OpenProjectModal.test.tsx+++ b/src/components/ai-edition/OpenProjectModal.test.tsx@@ -77,3 +77,47 @@ describe("OpenProjectModal delete", () => {expect(onSelect).toHaveBeenCalledWith("proj_one");});});++describe("OpenProjectModal keyboard (#1135)", () => {+ afterEach(() => {+ cleanup();+ vi.clearAllMocks();+ });++ it("opens the only match of a search on Enter", () => {+ const { onSelect } = renderModal();+ const search = screen.getByRole("searchbox");++ fireEvent.change(search, { target: { value: "second" } });+ fireEvent.keyDown(search, { key: "Enter" });++ expect(onSelect).toHaveBeenCalledWith("proj_two");+ });++ it("highlights the first match of a search, and ↑↓ move the highlight", () => {+ const { onSelect } = renderModal();+ const search = screen.getByRole("searchbox");++ fireEvent.change(search, { target: { value: "project" } });+ const highlightedTitle = () =>+ document.querySelector('[aria-current="true"]')?.textContent ?? "";+ expect(highlightedTitle()).toContain("First project");++ fireEvent.keyDown(search, { key: "ArrowDown" });+ expect(highlightedTitle()).toContain("Second project");+ // The last row holds.+ fireEvent.keyDown(search, { key: "ArrowDown" });+ fireEvent.keyDown(search, { key: "Enter" });++ expect(onSelect).toHaveBeenCalledWith("proj_two");+ });++ it("leaves Enter on a focused row button to the button itself", () => {+ const { onSelect } = renderModal();++ const row = screen.getByText("Second project").closest("button") as HTMLButtonElement;+ fireEvent.keyDown(row, { key: "Enter" });++ expect(onSelect).not.toHaveBeenCalled();+ });+});