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 }) {/* 中间:搜索容器 */}
-
- +
+ void }) onFocus={() => setShowResults(true)} onKeyDown={handleKeyDown} aria-label={t('common_buttons_search')} - className="w-full h-9 pl-9 pr-8 text-sm rounded-md border border-input bg-muted/50 transition-all placeholder:text-muted-foreground focus:bg-background focus:outline-none focus:ring-1 focus:ring-ring focus:border-input" + className="w-full h-9 pl-9 pr-16 text-sm rounded-lg border border-border/60 bg-muted/40 transition-all placeholder:text-muted-foreground/50 focus:bg-background focus:outline-none focus:ring-1 focus:ring-ring focus:border-input" /> + {!searchQuery && ( + + ⌘K + + )} {searchQuery && (