From ec4c0e8d3b0291b8b81fa7a361124dc1494c4c8b Mon Sep 17 00:00:00 2001 From: Nicholas Charriere Date: Fri, 12 Jul 2024 14:20:16 -0700 Subject: [PATCH] Ability to submit the generate form with cmd+enter (#131) --- .../web/src/components/generate-srcbook-modal.tsx | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/packages/web/src/components/generate-srcbook-modal.tsx b/packages/web/src/components/generate-srcbook-modal.tsx index 3cb99463..5545dfa6 100644 --- a/packages/web/src/components/generate-srcbook-modal.tsx +++ b/packages/web/src/components/generate-srcbook-modal.tsx @@ -1,4 +1,5 @@ import { useState } from 'react'; +import { useHotkeys } from 'react-hotkeys-hook'; import { useNavigate } from 'react-router-dom'; import { cn } from '@/lib/utils'; import { Button } from '@/components/ui/button'; @@ -29,7 +30,17 @@ export default function GenerateSrcbookModal({ const navigate = useNavigate(); + useHotkeys( + 'mod+enter', + () => { + if (!open) return; + generate(); + }, + { enableOnFormTags: ['textarea'] }, + ); + const generate = async () => { + if (!query) return; setStatus('loading'); const result = await onGenerate(query); if (result) {