From ab3e2e7230c2559530a375df270aaaf23e567366 Mon Sep 17 00:00:00 2001 From: cc Date: Thu, 19 Nov 2026 19:14:51 +0100 Subject: [PATCH] feat(keys): copy a key from the list A copy button appears on row hover; keyboard users press Cmd/Ctrl+C on a focused key (unless text is selected). The button stays out of the tab order so each key costs one tab stop, not two. Co-Authored-By: Claude Opus 5.5 --- src/components/key-link.tsx | 114 +++++++++++++++++++++++++++--------- 1 file changed, 87 insertions(+), 27 deletions(-) diff --git a/src/components/key-link.tsx b/src/components/key-link.tsx index 0a81464..f259cd9 100644 --- a/src/components/key-link.tsx +++ b/src/components/key-link.tsx @@ -1,5 +1,8 @@ -import { Minus, Plus } from "lucide-react"; +"use client"; + +import { Check, Copy, Minus, Plus } from "lucide-react"; import Link from "next/link"; +import { useEffect, useState } from "react"; import { cn } from "@/lib/utils"; @@ -14,40 +17,97 @@ export function KeyLink({ entry }: { entry: DisplayedKey }) { const isRemoved = entry.status === "removed"; return ( - - {(isNew || isRemoved) && ( - - {isRemoved ? ( - + { + // ⌘C / Ctrl+C on a focused key copies it (unless text is selected). + if ( + event.key === "c" && + (event.metaKey || event.ctrlKey) && + !window.getSelection()?.toString() + ) { + event.preventDefault(); + void navigator.clipboard.writeText(entry.key); + } + }} + > + {(isNew || isRemoved) && ( + + {isRemoved ? ( + + )} + + + + + ); +} + +/** + * Icon button revealed on row hover. Kept out of the tab order so keys don't + * cost two stops each; keyboard users copy with ⌘C / Ctrl+C on the link. + */ +function CopyKey({ text }: { text: string }) { + const [copied, setCopied] = useState(false); + + useEffect(() => { + if (!copied) return; + const timer = setTimeout(() => setCopied(false), 1500); + return () => clearTimeout(timer); + }, [copied]); + + return ( + ); }