diff --git a/src/components/TopBar.tsx b/src/components/TopBar.tsx index e9cdba9..99f15c6 100644 --- a/src/components/TopBar.tsx +++ b/src/components/TopBar.tsx @@ -49,6 +49,19 @@ export default function TopBar({ onOpenOptions }: { onOpenOptions: () => void }) return () => document.removeEventListener('mousedown', handleClickOutside); }, []); + // Cmd/Ctrl+K 快捷键聚焦搜索框 + useEffect(() => { + const handleGlobalKeyDown = (e: KeyboardEvent) => { + if ((e.metaKey || e.ctrlKey) && e.key === 'k') { + e.preventDefault(); + inputRef.current?.focus(); + setShowResults(true); + } + }; + document.addEventListener('keydown', handleGlobalKeyDown); + return () => document.removeEventListener('keydown', handleGlobalKeyDown); + }, []); + useEffect(() => { storageUtil .get('app/searchHistory', []) @@ -153,8 +166,8 @@ export default function TopBar({ onOpenOptions }: { onOpenOptions: () => void }) {/* 中间:搜索容器 */}