From 31cc3079a8e7beeb947b17f8cc58601ab965beca Mon Sep 17 00:00:00 2001 From: michalcourson Date: Sun, 1 Mar 2026 17:31:14 -0500 Subject: [PATCH] kinda bad, but functional delete on enter --- .../Trimmer/dialogs/DeleteClipDialog.tsx | 38 ++++++++++++++++++- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/electron-ui/src/renderer/components/Trimmer/dialogs/DeleteClipDialog.tsx b/electron-ui/src/renderer/components/Trimmer/dialogs/DeleteClipDialog.tsx index 6e5f1ec..93f7a1d 100644 --- a/electron-ui/src/renderer/components/Trimmer/dialogs/DeleteClipDialog.tsx +++ b/electron-ui/src/renderer/components/Trimmer/dialogs/DeleteClipDialog.tsx @@ -1,3 +1,4 @@ +import React from 'react'; import { Dialog, DialogTitle, @@ -14,6 +15,34 @@ export default function DeleteClipDialog({ onCancel: () => void; onDelete: () => void; }) { + const cancelRef = React.useRef(null); + const deleteRef = React.useRef(null); + const [focusedIdx, setFocusedIdx] = React.useState(1); // 0: Cancel, 1: Delete + + // Focus Delete on open + React.useEffect(() => { + if (open) { + setFocusedIdx(1); + setTimeout(() => { + deleteRef.current?.focus(); + }, 0); + } + }, [open]); + + // Keyboard navigation + const handleKeyDown = (e: React.KeyboardEvent) => { + if (e.key === 'Tab') { + e.preventDefault(); + const nextIdx = (focusedIdx + 1) % 2; + setFocusedIdx(nextIdx); + if (nextIdx === 0) cancelRef.current?.focus(); + else deleteRef.current?.focus(); + } else if (e.key === 'Enter') { + if (focusedIdx === 0) onCancel(); + else onDelete(); + } + }; + return ( Confirm Delete Are you sure you want to delete this clip?