From 092703a9a0e61e22cbd779760ee758912291242d Mon Sep 17 00:00:00 2001 From: DuroCodes Date: Wed, 23 Apr 2025 13:10:57 -0400 Subject: [PATCH] feat: add save button keybind --- src/components/save-button.tsx | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/components/save-button.tsx b/src/components/save-button.tsx index 8b8bf54..c88ad05 100644 --- a/src/components/save-button.tsx +++ b/src/components/save-button.tsx @@ -4,6 +4,7 @@ import { useRouter } from "next/navigation"; import { toast } from "sonner"; import { Button } from "~/components/ui/button"; import { addPaste } from "~/actions/paste-action"; +import { useEffect } from "react"; interface SaveButtonProps { content: string; @@ -38,6 +39,17 @@ export function SaveButton({ } }; + useEffect(() => { + const handleKeyDown = (e: KeyboardEvent) => { + if (e.key !== "s" || !(e.ctrlKey || e.metaKey)) return; + e.preventDefault(); + handleSave(); + }; + + window.addEventListener("keydown", handleKeyDown); + return () => window.removeEventListener("keydown", handleKeyDown); + }, [content, language, theme]); + return (