feat: add save button keybind

This commit is contained in:
DuroCodes
2025-04-23 13:10:57 -04:00
parent ee4a18e541
commit 092703a9a0

View File

@@ -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 (
<Button variant="outline" onClick={handleSave} className={className}>
save